作者 竞泽

add:part

  1 +{
  2 + "name": "lackoxygen/gz-cbec",
  3 + "type": "library",
  4 + "description": "广州单一窗口跨境电商",
  5 + "license": "MIT",
  6 + "authors": [
  7 + {
  8 + "name": "jz",
  9 + "email": "jingzeou@outlook.com"
  10 + }
  11 + ],
  12 + "require": {
  13 + "php": ">=7.1",
  14 + "illuminate/support": "^5.8"
  15 + },
  16 + "require-dev": {
  17 + "phpunit/phpunit": "~4.0"
  18 + },
  19 + "autoload": {
  20 + "psr-4": {
  21 + "Lackoxygen\\GzCbec\\": "src/"
  22 + }
  23 + },
  24 + "extra": {
  25 + "laravel": {
  26 + "providers": [
  27 + "Lackoxygen\\TopWarehouse\\TopWarehouseServiceProvider"
  28 + ]
  29 + }
  30 + }
  31 +}
@@ -27,14 +27,7 @@ class Client implements ClientInterface @@ -27,14 +27,7 @@ class Client implements ClientInterface
27 /** 27 /**
28 * @var array 28 * @var array
29 */ 29 */
30 - protected $config = [  
31 - 'base_uri' => 'https://open.singlewindow.gz.cn',  
32 - 'record_sn' => 'C011111100414353',  
33 - 'secret_key' => '12345678',  
34 - 'company_cert_sn' => '20200000000652',  
35 - 'sender_sn' => 'GEYOUSUOAI',  
36 - 'receiver_sn' => 'KJPUBLICPT'  
37 - ]; 30 + protected $config = [];
38 31
39 protected function __construct(RequestInterface $request) 32 protected function __construct(RequestInterface $request)
40 { 33 {
@@ -43,6 +36,7 @@ class Client implements ClientInterface @@ -43,6 +36,7 @@ class Client implements ClientInterface
43 'verify' => false 36 'verify' => false
44 ]); 37 ]);
45 $this->request = $request; 38 $this->request = $request;
  39 + $this->config = config('gz-cbec');
46 } 40 }
47 41
48 /** 42 /**
@@ -63,7 +57,6 @@ class Client implements ClientInterface @@ -63,7 +57,6 @@ class Client implements ClientInterface
63 public function send(): ResponseInterface 57 public function send(): ResponseInterface
64 { 58 {
65 $content = $this->request->getPacket()->getContent(); 59 $content = $this->request->getPacket()->getContent();
66 - file_put_contents('transfer.xml', $content);  
67 try { 60 try {
68 $response = $this->guzzleHttp->request($this->request->getMethod(), $this->request->getPath(), [ 61 $response = $this->guzzleHttp->request($this->request->getMethod(), $this->request->getPath(), [
69 RequestOptions::FORM_PARAMS => [ 62 RequestOptions::FORM_PARAMS => [
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec;
  5 +
  6 +
  7 +class GzCBECProvider
  8 +{
  9 + /**
  10 + * @var bool
  11 + */
  12 + protected $defer = true;
  13 +
  14 + /**
  15 + * @var array
  16 + */
  17 + protected $commands = [];
  18 +
  19 + /**
  20 + * Register any application services.
  21 + *
  22 + * @return void
  23 + */
  24 + public function register()
  25 + {
  26 + $this->commands($this->commands);
  27 + }
  28 +
  29 + public function boot()
  30 + {
  31 + $this->publishes([__DIR__ . '/../config/gz-cbec.php' => config_path('gz-cbec.php')]);
  32 + }
  33 +
  34 + /**
  35 + * @return string[]
  36 + */
  37 + public function provides()
  38 + {
  39 + return ['gzCbec', GzCBEC::class];
  40 + }
  41 +}
@@ -36,15 +36,7 @@ class Packet @@ -36,15 +36,7 @@ class Packet
36 { 36 {
37 $this->request = $request; 37 $this->request = $request;
38 38
39 - $this->config = [  
40 - 'base_uri' => 'https://open.singlewindow.gz.cn',  
41 - 'record_sn' => 'C011111100414353',  
42 - 'secret_key' => '12345678',  
43 - 'company_cert_sn' => '20200000000652',  
44 - 'sender_sn' => 'GEYOUSUOAI',  
45 - 'receiver_sn' => 'KJPUBLICPT',  
46 - 'signature' => "http://10.10.10.41:8080/signature.do"  
47 - ]; 39 + $this->config = config('gz-cbec');
48 } 40 }
49 41
50 42
1 -<?php  
2 -  
3 -  
4 -namespace Lackoxygen\GzCbec\Utils;  
5 -  
6 -  
7 -use Lackoxygen\GzCbec\Exception\Exception;  
8 -  
9 -class RSA  
10 -{  
11 - /**  
12 - * @param $key  
13 - *  
14 - * @return string  
15 - */  
16 - public static function trimKey($key): string  
17 - {  
18 - return wordwrap(preg_replace('/[\r\n]/', '', $key), 64, "\n", true);  
19 - }  
20 -  
21 - /**  
22 - * @param $data  
23 - * @param $key  
24 - *  
25 - * @return mixed  
26 - */  
27 - public static function signPrivate($data, $key)  
28 - {  
29 - $key = self::trimKey($key);  
30 - $key = "-----BEGIN RSA PRIVATE KEY-----\n{$key}\n-----END RSA PRIVATE KEY-----";  
31 - openssl_sign($data, $sign, $key, \OPENSSL_ALGO_SHA1);  
32 -  
33 - return $sign;  
34 - }  
35 -  
36 - /**  
37 - * @param $data  
38 - * @param $fileName  
39 - *  
40 - * @return mixed  
41 - * @throws Exception  
42 - */  
43 - public static function signPrivateFromFile($data, $fileName)  
44 - {  
45 - $key = file_get_contents($fileName);  
46 - $res = openssl_get_privatekey($key);  
47 - if (!$res) {  
48 - throw new Exception('Incorrect public key file format');  
49 - }  
50 - openssl_sign($data, $sign, $res, \OPENSSL_ALGO_SHA1);  
51 - openssl_free_key($res);  
52 -  
53 - return $sign;  
54 - }  
55 -  
56 - /**  
57 - * @param $data  
58 - * @param $key  
59 - * @param $sign  
60 - *  
61 - * @return bool  
62 - */  
63 - public static function verifyPublic($data, $key, $sign)  
64 - {  
65 - $key = static::trimKey($key);  
66 - $key = "-----BEGIN PUBLIC KEY-----\n{$key}\n-----END PUBLIC KEY-----";  
67 -  
68 - return 1 === openssl_verify($data, $sign, $key, \OPENSSL_ALGO_SHA1);  
69 - }  
70 -  
71 - /**  
72 - * @param $data  
73 - * @param $fileName  
74 - * @param $sign  
75 - *  
76 - * @return bool  
77 - * @throws Exception  
78 - */  
79 - public static function verifyPublicFromFile($data, $fileName, $sign): bool  
80 - {  
81 - $key = file_get_contents($fileName);  
82 - $res = openssl_get_publickey($key);  
83 - if (!$res) {  
84 - throw new Exception('Incorrect public key file format');  
85 - }  
86 - $result = openssl_verify($data, $sign, $res, \OPENSSL_ALGO_SHA1);  
87 - openssl_free_key($res);  
88 -  
89 - return 1 === $result;  
90 - }  
91 -  
92 - /**  
93 - * @param $data  
94 - * @param $fileName  
95 - *  
96 - * @return mixed  
97 - * @throws Exception  
98 - */  
99 - public static function encryptPublicFromFile($data, $fileName)  
100 - {  
101 - $res = openssl_get_publickey(file_get_contents($fileName));  
102 - if (!$res) {  
103 - throw new Exception('公钥文件格式错误');  
104 - }  
105 - openssl_public_encrypt($data, $result, $res, \OPENSSL_PKCS1_OAEP_PADDING);  
106 - openssl_free_key($res);  
107 -  
108 - return $result;  
109 - }  
110 -  
111 - /**  
112 - * @param $data  
113 - * @param $public  
114 - *  
115 - * @return mixed  
116 - */  
117 - public static function encryptPublic($data, $public)  
118 - {  
119 - openssl_public_encrypt($data, $result, $public, \OPENSSL_PKCS1_OAEP_PADDING);  
120 -  
121 - return $result;  
122 - }  
123 -}