├── .gitignore ├── composer.json ├── src └── ChenPay │ ├── PayException │ └── PayException.php │ ├── Cookie.php │ ├── Pay.php │ ├── WxPay.php │ └── AliPay.php ├── LICENSE ├── test └── test.php └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | */.DS_Store 2 | .DS_Store 3 | /vendor 4 | /composer.lock 5 | /.idea -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chen-see/chen-pay", 3 | "description": "免签约支付宝与微信双支付,根据COOKIE", 4 | "keywords": [ 5 | "alipay", 6 | "wxpay", 7 | "chenpay" 8 | ], 9 | "license": "MIT", 10 | "homepage": "http://9in.info", 11 | "require": { 12 | "php": ">=5.5", 13 | "guzzlehttp/guzzle": "^6.3" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "ChenPay\\": "src/ChenPay" 18 | } 19 | }, 20 | "extra": { 21 | "branch-alias": { 22 | "dev-master": "1.0" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/ChenPay/PayException/PayException.php: -------------------------------------------------------------------------------- 1 | code}]: {$this->message}\n"; 20 | } 21 | 22 | public function customFunction() 23 | { 24 | echo "A custom function for this type of exception\n"; 25 | } 26 | } -------------------------------------------------------------------------------- /src/ChenPay/Cookie.php: -------------------------------------------------------------------------------- 1 | cookie = $cookie; 20 | } 21 | 22 | abstract protected function getData($url, $syncKey); 23 | 24 | abstract protected function DataHandle(); 25 | 26 | abstract protected function DataContrast($fee, $time, $Minute); 27 | 28 | public static function Listen($s, $func) 29 | { 30 | ignore_user_abort(); 31 | set_time_limit(0); 32 | do { 33 | $func(); 34 | sleep($s); 35 | } while (true); 36 | } 37 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Chen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /test/test.php: -------------------------------------------------------------------------------- 1 | 0.01, 'time' => time() + 3 * 60]]; 19 | if ($GLOBALS['AliStatus'] > time() && count($data) == 0) return; 20 | try { 21 | $run = (new ChenPay\AliPay($AliCookie))->getData($GLOBALS['AliType'])->DataHandle(); 22 | foreach ($data as $item) { 23 | $Remarks = '123456'; //如果需要判断备注 24 | $order = $run->DataContrast($item['fee'], $item['time'], 5, $Remarks); 25 | if ($order) echo "{$order}订单有效!备注:{$Remarks}\n"; 26 | unset($order, $item);// 摧毁变量防止内存溢出 27 | } 28 | echo $GLOBALS['AliSum'] . "次运行\n"; 29 | $GLOBALS['AliType'] = !$GLOBALS['AliType']; 30 | $GLOBALS['AliSum']++; 31 | $GLOBALS['AliStatus'] = time() + 2 * 60; // 32 | } catch (\ChenPay\PayException\PayException $e) { 33 | echo $e->getMessage() . "\n"; 34 | unset($e);// 摧毁变量防止内存溢出 35 | } 36 | unset($run, $data);// 摧毁变量防止内存溢出 37 | }); 38 | 39 | $GLOBALS['WxSum'] = 1; 40 | $GLOBALS['syncKey'] = false; 41 | ChenPay\Pay::Listen(10, function () use ($WxCookie) { 42 | // time 现在时间此为订单生成时间 默认3分钟有效时间 43 | $data = [['fee' => 0.01, 'time' => time() + 3 * 60]]; 44 | try { 45 | $run = (new ChenPay\WxPay($WxCookie))->getData('wx.qq.com', $GLOBALS['syncKey'])->DataHandle(); 46 | $GLOBALS['syncKey'] = $run->syncKey; 47 | foreach ($data as $item) { 48 | $Remarks = '123456'; //如果需要判断备注 49 | $order = $run->DataContrast($item['fee'], $item['time'], 3, $Remarks); 50 | if ($order) echo "{$order}订单有效!备注:{$Remarks}\n"; 51 | unset($order, $item);// 摧毁变量防止内存溢出 52 | } 53 | echo $GLOBALS['WxSum'] . "次运行\n"; 54 | $GLOBALS['WxSum']++; 55 | } catch (\ChenPay\PayException\PayException $e) { 56 | echo $e->getMessage() . "\n"; 57 | unset($e);// 摧毁变量防止内存溢出 58 | } 59 | unset($run, $data);// 摧毁变量防止内存溢出 60 | }); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 欢迎使用 **composer** 免签约支付宝与微信 带监听 2 | 3 | - 免签约支付宝 根据COOKIE 4 | - 免签约微信支付 根据COOKIE 5 | - 实时到帐个人账户 6 | - PHP程序自监听 7 | ### 讨论群 8 | https://t.me/chenAirport 9 | ### DEMO测试 10 | https://pay.n2.nu 11 | 12 | ### composer安装: 13 | ``` 14 | composer require chen-see/chen-pay 15 | ``` 16 | 17 | ### 使用教程: 18 | ```php 19 | include __DIR__ . '/../vendor/autoload.php'; 20 | $AliCookie = ''; 21 | $WxCookie = ''; 22 | 23 | $GLOBALS['AliSum'] = 1; 24 | $GLOBALS['AliType'] = true; // 支付宝接口切换 25 | $GLOBALS['AliStatus'] = time(); // 暂停 有订单情况下才是10秒一次的频率 杜绝支付宝风控 26 | ChenPay\Pay::Listen(10, function () use ($AliCookie) { 27 | // time 现在时间此为订单生成时间 默认3分钟有效时间 28 | $data = [['fee' => 0.01, 'time' => time() + 3 * 60]]; 29 | if ($GLOBALS['AliStatus'] > time() && count($data) == 0) return; 30 | try { 31 | $run = (new ChenPay\AliPay($AliCookie))->getData($GLOBALS['AliType'])->DataHandle(); 32 | foreach ($data as $item) { 33 | $Remarks = '123456'; //如果需要判断备注 34 | $order = $run->DataContrast($item['fee'], $item['time'], 5, $Remarks); 35 | if ($order) echo "{$order}订单有效!备注:{$Remarks}\n"; 36 | unset($order, $item);// 摧毁变量防止内存溢出 37 | } 38 | echo $GLOBALS['AliSum'] . "次运行\n"; 39 | $GLOBALS['AliType'] = !$GLOBALS['AliType']; 40 | $GLOBALS['AliSum']++; 41 | $GLOBALS['AliStatus'] = time() + 2 * 60; // 42 | } catch (\ChenPay\PayException\PayException $e) { 43 | echo $e->getMessage() . "\n"; 44 | unset($e);// 摧毁变量防止内存溢出 45 | } 46 | unset($run, $data);// 摧毁变量防止内存溢出 47 | }); 48 | 49 | $GLOBALS['WxSum'] = 1; 50 | $GLOBALS['syncKey'] = false; 51 | ChenPay\Pay::Listen(10, function () use ($WxCookie) { 52 | // time 现在时间此为订单生成时间 默认3分钟有效时间 53 | $data = [['fee' => 0.01, 'time' => time() + 3 * 60]]; 54 | try { 55 | $run = (new ChenPay\WxPay($WxCookie))->getData('wx.qq.com', $GLOBALS['syncKey'])->DataHandle(); 56 | $GLOBALS['syncKey'] = $run->syncKey; 57 | foreach ($data as $item) { 58 | $Remarks = '123456'; //如果需要判断备注 59 | $order = $run->DataContrast($item['fee'], $item['time'], 3, $Remarks); 60 | if ($order) echo "{$order}订单有效!备注:{$Remarks}\n"; 61 | unset($order, $item);// 摧毁变量防止内存溢出 62 | } 63 | echo $GLOBALS['WxSum'] . "次运行\n"; 64 | $GLOBALS['WxSum']++; 65 | } catch (\ChenPay\PayException\PayException $e) { 66 | echo $e->getMessage() . "\n"; 67 | unset($e);// 摧毁变量防止内存溢出 68 | } 69 | unset($run, $data);// 摧毁变量防止内存溢出 70 | }); 71 | ``` 72 | 73 | ### 获取支付宝COOKIE 74 | - 浏览器访问:https://mbillexprod.alipay.com/enterprise/tradeListQuery.htm 75 | - 登录支付宝账号 76 | - 浏览器按f12 77 | - 找到Network并点击再刷新一下 78 | - 可以看到tradeListQuery.json点击它 79 | - 点击headers它找到Cookie: 后面就是cookie(务必复制完整) 80 | 81 | ### 获取微信COOKIE 82 | - 浏览器访问:https://wx.qq.com(此地址必须设置到后台支付设置里,登录完成后会有所变更) 83 | - 手机扫码登录微信账号 84 | - 浏览器按f12 85 | - 找到Network并点击再刷新一下 86 | - 可以看到webwxinit?r=*******点击它 87 | - 点击headers它找到Cookie: 后面就是cookie(务必复制完整) 88 | 89 | ### 运行: 90 | ``` 91 | # 前台运行 92 | php test/test.php 93 | # 后台运行 94 | nohup php test/test.php & 95 | ``` 96 | 97 | ### 请我喝杯奶茶呗 98 | ![捐赠](http://ww1.sinaimg.cn/large/006v0omggy1fyfl7ilcj5j30go08c0tu.jpg) 99 | ## 注意: 100 | 101 | - 根据备注可判断相同价格多人支付(出现相同价格的多并发支付时可要求用户输入随机数字备注解决该问题) 102 | - 两个支付必须分开运行,demo只是作为演示 103 | - 服务器时间必须是国内的时间,不然对不上支付宝微信时间 104 | - 如果使用框架运行可能存在内存溢出问题,可以使用Crontab,请自行去除```ChenPay\Pay::Listen```函数,变量需要另外选择存储方式mysql\redis等 105 | 106 | ## 更新日志: 107 | ### V1.0.5 108 | - 更新支付宝双接口轮流切换API达到支付宝防止频繁访问阻止机制 109 | - 如果单一接口出现阻止则会持续使用另外接口 110 | ### V1.0.6 111 | - 增加支付宝频繁错误码446 112 | ### V1.0.7 113 | - 10秒超时时间 114 | ### V1.0.9 115 | - 支付宝商户订单号改成支付宝交易号 116 | ### V1.1.1 117 | - 应对11月支付宝升级导致账号失效问题 118 | ### V1.2 119 | - 增加判断备注&设置时区 120 | ### readme更新 121 | - 有订单情况下才是10秒一次的频率 杜绝支付宝风控 122 | -------------------------------------------------------------------------------- /src/ChenPay/WxPay.php: -------------------------------------------------------------------------------- 1 | request('POST', "https://" . $this->url . "/cgi-bin/mmwebwx-bin/webwxinit?r=695888609", [ 29 | 'timeout' => 10, 30 | 'headers' => [ 31 | 'Accept' => 'application/json, text/javascript', 32 | 'Accept-Encoding' => 'gzip, deflate, br', 33 | 'Accept-Language' => 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7', 34 | 'Connection' => 'keep-alive', 35 | 'Content-Length' => '295', 36 | 'Content-Type' => 'application/json;charset=UTF-8', 37 | 'Cookie' => $this->cookie, 38 | 'Host' => $this->url, 39 | 'Origin' => 'https://' . $this->url, 40 | 'Referer' => 'https://' . $this->url . '/', 41 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' 42 | ], 43 | 'body' => '{"BaseRequest":{"Uin":' . Cookie::getCookieName('wxuin', $this->cookie) . 44 | ',"Sid":"' . Cookie::getCookieName('wxsid', $this->cookie) . '","Skey":' . 45 | '"","DeviceID":"e453731506754000"}}' 46 | ]) 47 | ->getBody(); 48 | return json_decode($html->getContents(), true); 49 | } catch (GuzzleException $e) { 50 | throw new PayException('访问出错', 500); 51 | } catch (PayException $e) { 52 | throw new PayException($e->getMessage(), $e->getCode()); 53 | } catch (\Exception $e) { 54 | throw new PayException('处理出错', 444); 55 | } 56 | } 57 | 58 | /** 59 | * @param $url 60 | * @param $syncKey 61 | * @return $this 62 | * @throws PayException 63 | */ 64 | public function getData($url, $syncKey = false) 65 | { 66 | // TODO: Implement getData() method. 67 | $this->url = $url; 68 | if (!$syncKey || preg_match('/"Count"\:0/', $syncKey)) { 69 | $syncJson = $this->getSyncKey(); 70 | if ($syncJson['BaseResponse']['Ret'] > 0) throw new PayException('cookie失效', 445); 71 | $sync = json_encode($syncJson['SyncKey']); 72 | } else $sync = $syncKey; 73 | try { 74 | $html = (new \GuzzleHttp\Client()) 75 | ->request('POST', "https://" . $this->url . "/cgi-bin/mmwebwx-bin/webwxsync?sid=" . 76 | Cookie::getCookieName('wxsid', $this->cookie) . "&skey=", [ 77 | 'timeout' => 10, 78 | 'headers' => [ 79 | 'Accept' => 'application/json, text/javascript', 80 | 'Accept-Encoding' => 'gzip, deflate, br', 81 | 'Accept-Language' => 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7', 82 | 'Connection' => 'keep-alive', 83 | 'Content-Length' => '295', 84 | 'Content-Type' => 'application/json;charset=UTF-8', 85 | 'Cookie' => $this->cookie, 86 | 'Host' => $this->url, 87 | 'Origin' => 'https://' . $this->url, 88 | 'Referer' => 'https://' . $this->url . '/', 89 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' 90 | ], 91 | 'body' => '{"BaseRequest":{"Uin":' . Cookie::getCookieName('wxuin', $this->cookie) . 92 | ',"Sid":"' . Cookie::getCookieName('wxsid', $this->cookie) . '","Skey":"' . 93 | '","DeviceID":"e453731506754000"},"SyncKey":' . $sync . 94 | ',"rr":' . rand(100000000, 999999999) . '}' 95 | ]) 96 | ->getBody(); 97 | $this->html = $html->getContents(); 98 | $this->syncKey = json_encode(json_decode($this->html, true)['SyncKey']); 99 | } catch (GuzzleException $e) { 100 | throw new PayException($e->getMessage(), 500); 101 | } catch (PayException $e) { 102 | throw new PayException($e->getMessage(), $e->getCode()); 103 | } catch (\Exception $e) { 104 | throw new PayException('处理出错', 444); 105 | } 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return $this 111 | * @throws PayException 112 | */ 113 | public function DataHandle() 114 | { 115 | try { 116 | $this->json = json_decode($this->html, true); 117 | } catch (\Exception $e) { 118 | throw new PayException('解析出错', 444); 119 | } 120 | if ($this->json['BaseResponse']['Ret'] > 0) 121 | throw new PayException('cookie失效', 445); 122 | return $this; 123 | } 124 | 125 | /** 126 | * 获取最新的订单号 127 | * @param $fee 128 | * @param $time 129 | * @param int $Minute 130 | * @param bool $Remarks 131 | * @return array|bool 132 | */ 133 | public function DataContrast($fee, $time, $Minute = 3, $Remarks = false) 134 | { 135 | // TODO: Implement DataContrast() method. 136 | if (isset($this->json['AddMsgList']) && is_array($this->json['AddMsgList'])) 137 | foreach ($this->json['AddMsgList'] as $item) { 138 | if (preg_match('/微信支付收款/', $item['FileName'])) { 139 | $fees = explode('微信支付收款', $item['FileName']); 140 | $fees = explode('元', $fees[1])[0]; 141 | if ($item['CreateTime'] < $time && $item['CreateTime'] > $time - $Minute * 60 && 142 | $fees == $fee && ($Remarks === false || (($Remarks != '' && preg_match("/备注:{$Remarks}request('POST', "https://enterpriseportal.alipay.com/portal/navload.json?t=" . time() * 1000, [ 27 | 'timeout' => 10, 28 | 'headers' => [ 29 | 'Cookie' => $this->cookie, 30 | 'Accept-Encoding' => 'gzip, deflate, br', 31 | 'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7', 32 | 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36', 33 | 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 34 | 'Accept' => 'application/json, text/javascript', 35 | 'Referer' => 'https://mbillexprod.alipay.com/enterprise/tradeListQuery.htm', 36 | 'Origin' => 'https://mbillexprod.alipay.com', 37 | 'Connection' => 'keep-alive', 38 | ], 39 | 'body' => 'action=loadEntInfo' 40 | ]) 41 | ->getBody(); 42 | } catch (GuzzleException $e) { 43 | throw new PayException($e->getMessage(), 500); 44 | } 45 | if (!preg_match('/navResult/', $aliPayHtml)) throw new PayException('cookie失效', 445); 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return \Psr\Http\Message\StreamInterface 51 | * @throws PayException 52 | */ 53 | public function HtmlOne() 54 | { 55 | try { 56 | return (new \GuzzleHttp\Client()) 57 | ->request('POST', "https://mbillexprod.alipay.com/enterprise/tradeListQuery.json", [ 58 | 'timeout' => 10, 59 | 'headers' => [ 60 | 'Cookie' => $this->cookie, 61 | 'Origin' => 'https://mbillexprod.alipay.com', 62 | 'Accept-Encoding' => 'gzip, deflate, br', 63 | 'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7', 64 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', 65 | 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 66 | 'Accept' => 'application/json, text/javascript', 67 | 'Referer' => 'https://mbillexprod.alipay.com/enterprise/tradeListQuery.htm', 68 | 'X-Requested-With' => 'XMLHttpRequest', 69 | 'Connection' => 'keep-alive', 70 | ], 71 | 'body' => 'queryEntrance=1&billUserId=' . Cookie::getCookieName('uid', $this->cookie) . 72 | '&status=SUCCESS&entityFilterType=0&activeTargetSearchItem=tradeNo&tradeFrom=ALL&startTime=' . 73 | date('Y-m-d', strtotime('-1 day')) . '+00%3A00%3A00&endTime=' . date('Y-m-d') . 74 | '+23%3A59%3A59&pageSize=20&pageNum=1&total=1&sortTarget=gmtCreate&order=descend&sortType=0&_input_charset=gbk&ctoken=' . 75 | Cookie::getCookieName('ctoken', $this->cookie), 76 | ]) 77 | ->getBody(); 78 | } catch (GuzzleException $e) { 79 | throw new PayException($e->getMessage(), 500); 80 | } catch (PayException $e) { 81 | throw new PayException($e->getMessage(), 445); 82 | } 83 | } 84 | 85 | /** 86 | * @return \Psr\Http\Message\StreamInterface 87 | * @throws PayException 88 | */ 89 | public function HtmlTwo() 90 | { 91 | try { 92 | return (new \GuzzleHttp\Client()) 93 | ->request('POST', "https://mbillexprod.alipay.com/enterprise/fundAccountDetail.json", [ 94 | 'timeout' => 10, 95 | 'headers' => [ 96 | 'Cookie' => $this->cookie, 97 | 'Origin' => 'https://mbillexprod.alipay.com', 98 | 'Accept-Encoding' => 'gzip, deflate, br', 99 | 'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7', 100 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', 101 | 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 102 | 'Accept' => 'application/json, text/javascript', 103 | 'Referer' => 'https://mbillexprod.alipay.com/enterprise/fundAccountDetail.htm', 104 | 'X-Requested-With' => 'XMLHttpRequest', 105 | 'Connection' => 'keep-alive', 106 | ], 107 | 108 | 'body' => 'queryEntrance=1&billUserId=' . Cookie::getCookieName('uid', $this->cookie) . 109 | '&showType=1&type=&precisionQueryKey=tradeNo&' . 110 | 'startDateInput=' . date('Y-m-d', strtotime('-1 day')) . '+00%3A00%3A00&endDateInput=' . date('Y-m-d') . '+23%3A59%3A59&' . 111 | 'pageSize=20&pageNum=1&total=1&sortTarget=tradeTime&order=descend&sortType=0&' . 112 | '_input_charset=gbk&ctoken=' . Cookie::getCookieName('ctoken', $this->cookie) 113 | ]) 114 | ->getBody(); 115 | } catch (GuzzleException $e) { 116 | throw new PayException($e->getMessage(), 500); 117 | } catch (PayException $e) { 118 | throw new PayException($e->getMessage(), 445); 119 | } 120 | } 121 | 122 | /** 123 | * @param bool $url 124 | * @param bool $syncKey 125 | * @return $this 126 | * @throws PayException 127 | */ 128 | public function getData($url = false, $syncKey = false) 129 | { 130 | // TODO: Implement getData() method. 131 | $this->url = $url; 132 | $this->getRefresh(); 133 | $aliPayHtml = $url ? $this->HtmlOne()->getContents() : $this->HtmlTwo()->getContents(); 134 | if (preg_match('/"failed"/', $aliPayHtml)) { 135 | $aliPayHtml = !$url ? $this->HtmlOne()->getContents() : $this->HtmlTwo()->getContents(); 136 | if (preg_match('/"failed"/', $aliPayHtml)) throw new PayException('频繁访问', 446); 137 | $this->url = !$url; 138 | } 139 | try { 140 | $this->html = iconv('GBK', 'UTF-8', $aliPayHtml); 141 | } catch (\Exception $e) { 142 | throw new PayException('处理出错', 444); 143 | } 144 | return $this; 145 | } 146 | 147 | /** 148 | * @return $this 149 | * @throws PayException 150 | */ 151 | public function DataHandle() 152 | { 153 | try { 154 | $this->json = json_decode($this->html, true); 155 | } catch (\Exception $e) { 156 | throw new PayException('解析出错', 444); 157 | } 158 | // if (isset($this->json['exception_marking'])) throw new PayException('数据出错', 444); 159 | if (isset($this->json['target'])) throw new PayException('cookie失效', 445); 160 | return $this; 161 | } 162 | 163 | /** 164 | * 获取最新的订单号 165 | * @param $fee 166 | * @param $time 167 | * @param int $Minute 168 | * @param bool $Remarks 169 | * @return array|bool 170 | */ 171 | public function DataContrast($fee, $time, $Minute = 3, $Remarks = false) 172 | { 173 | // TODO: Implement DataContrast() method. 174 | // print_r($this->json['result']['detail']); 175 | if (isset($this->json['result']['detail']) && is_array($this->json['result']['detail'])) 176 | foreach ($this->json['result']['detail'] as $item) { 177 | if (( 178 | ($this->url && $item['tradeFrom'] == '外部商户' && $item['direction'] == '卖出' && 179 | strtotime($item['gmtCreate']) > $time - $Minute * 60 && strtotime($item['gmtCreate']) < $time && 180 | $item['totalAmount'] == $fee) || 181 | (!$this->url && $item['signProduct'] == '转账收款码' && $item['accountType'] == '交易' && 182 | strtotime($item['tradeTime']) > $time - $Minute * 60 && strtotime($item['tradeTime']) < $time && 183 | $item['tradeAmount'] == $fee) 184 | ) && ($Remarks === false || ($Remarks != '' && (preg_match("/{$Remarks}/", $item['goodsTitle'])) || 185 | ($Remarks == '' && $item['goodsTitle'] == '商品')))) { 186 | return $item['tradeNo']; 187 | } 188 | } 189 | 190 | return false; 191 | } 192 | } --------------------------------------------------------------------------------