From 8132fc55b9412059cc1da403f0090b4db01e6fb9 Mon Sep 17 00:00:00 2001 From: Anyon <zoujingli@qq.com> Date: Wed, 21 Nov 2018 14:34:28 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]ComposerUpdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/view/plugs/icon.html | 1 + vendor/autoload.php | 2 +- vendor/composer/autoload_classmap.php | 2 +- vendor/composer/autoload_real.php | 14 +-- vendor/composer/autoload_static.php | 10 +- vendor/composer/installed.json | 12 +- .../wechat-developer/AliPay/Bill.php | 2 +- vendor/zoujingli/wechat-developer/README.md | 110 ++++++++++++++++++ vendor/zoujingli/wechat-developer/We.php | 2 +- .../WeChat/Contracts/BasicAliPay.php | 92 +++++++++------ .../wechat-developer/_test/alipay-app.php | 3 +- .../wechat-developer/_test/alipay-notify.php | 32 ++--- .../wechat-developer/_test/alipay-wap.php | 3 +- .../wechat-developer/_test/alipay-web.php | 3 +- .../wechat-developer/_test/alipay.php | 15 ++- .../wechat-developer/_test/config.php | 2 +- .../_test/wechat-user-get.php | 1 + 17 files changed, 224 insertions(+), 82 deletions(-) diff --git a/application/admin/view/plugs/icon.html b/application/admin/view/plugs/icon.html index febc3a22b..b743fb1bf 100644 --- a/application/admin/view/plugs/icon.html +++ b/application/admin/view/plugs/icon.html @@ -93,6 +93,7 @@ white-space: nowrap } </style> + </head> <body> <ul class="site-doc-icon"> diff --git a/vendor/autoload.php b/vendor/autoload.php index 30eb7b7cd..7fd8229e0 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitbe36bc09417ef093d568a98d90fda606::getLoader(); +return ComposerAutoloaderInit80a18f8002995aad6375cb55e92e2645::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 60cfb756e..5bbd0768a 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -184,7 +184,7 @@ return array( 'app\\admin\\controller\\Node' => $baseDir . '/application/admin/controller/Node.php', 'app\\admin\\controller\\Plugs' => $baseDir . '/application/admin/controller/Plugs.php', 'app\\admin\\controller\\User' => $baseDir . '/application/admin/controller/User.php', - 'app\\admin\\logic\\Auth' => $baseDir . '/application/admin/logic/Auth.php', + 'app\\admin\\middleware\\Auth' => $baseDir . '/application/admin/middleware/Auth.php', 'app\\index\\controller\\Index' => $baseDir . '/application/index/controller/Index.php', 'app\\store\\controller\\Express' => $baseDir . '/application/store/controller/Express.php', 'app\\store\\controller\\Goods' => $baseDir . '/application/store/controller/Goods.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 240ba7772..ec21f5fab 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitef946a60869007e79afc4c4e78c26e16 +class ComposerAutoloaderInit80a18f8002995aad6375cb55e92e2645 { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInitef946a60869007e79afc4c4e78c26e16 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitef946a60869007e79afc4c4e78c26e16', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit80a18f8002995aad6375cb55e92e2645', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInitef946a60869007e79afc4c4e78c26e16', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit80a18f8002995aad6375cb55e92e2645', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitef946a60869007e79afc4c4e78c26e16::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit80a18f8002995aad6375cb55e92e2645::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInitef946a60869007e79afc4c4e78c26e16 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitef946a60869007e79afc4c4e78c26e16::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit80a18f8002995aad6375cb55e92e2645::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequireef946a60869007e79afc4c4e78c26e16($fileIdentifier, $file); + composerRequire80a18f8002995aad6375cb55e92e2645($fileIdentifier, $file); } return $loader; } } -function composerRequireef946a60869007e79afc4c4e78c26e16($fileIdentifier, $file) +function composerRequire80a18f8002995aad6375cb55e92e2645($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index b01dff648..8e02a9605 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitef946a60869007e79afc4c4e78c26e16 +class ComposerStaticInit80a18f8002995aad6375cb55e92e2645 { public static $files = array ( '1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php', @@ -282,7 +282,7 @@ class ComposerStaticInitef946a60869007e79afc4c4e78c26e16 'app\\admin\\controller\\Node' => __DIR__ . '/../..' . '/application/admin/controller/Node.php', 'app\\admin\\controller\\Plugs' => __DIR__ . '/../..' . '/application/admin/controller/Plugs.php', 'app\\admin\\controller\\User' => __DIR__ . '/../..' . '/application/admin/controller/User.php', - 'app\\admin\\logic\\Auth' => __DIR__ . '/../..' . '/application/admin/logic/Auth.php', + 'app\\admin\\middleware\\Auth' => __DIR__ . '/../..' . '/application/admin/middleware/Auth.php', 'app\\index\\controller\\Index' => __DIR__ . '/../..' . '/application/index/controller/Index.php', 'app\\store\\controller\\Express' => __DIR__ . '/../..' . '/application/store/controller/Express.php', 'app\\store\\controller\\Goods' => __DIR__ . '/../..' . '/application/store/controller/Goods.php', @@ -320,9 +320,9 @@ class ComposerStaticInitef946a60869007e79afc4c4e78c26e16 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitef946a60869007e79afc4c4e78c26e16::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitef946a60869007e79afc4c4e78c26e16::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitef946a60869007e79afc4c4e78c26e16::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit80a18f8002995aad6375cb55e92e2645::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit80a18f8002995aad6375cb55e92e2645::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit80a18f8002995aad6375cb55e92e2645::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index d511cfca1..630ae6789 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -443,17 +443,17 @@ }, { "name": "zoujingli/wechat-developer", - "version": "v1.2.4", - "version_normalized": "1.2.4.0", + "version": "v1.2.6", + "version_normalized": "1.2.6.0", "source": { "type": "git", "url": "https://github.com/zoujingli/WeChatDeveloper.git", - "reference": "ace4ce3949821588c34641fbadda4461725b5fbe" + "reference": "e6be8222c2be8e70515876affd966ec1d22cc65d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/WeChatDeveloper/zipball/ace4ce3949821588c34641fbadda4461725b5fbe", - "reference": "ace4ce3949821588c34641fbadda4461725b5fbe", + "url": "https://api.github.com/repos/zoujingli/WeChatDeveloper/zipball/e6be8222c2be8e70515876affd966ec1d22cc65d", + "reference": "e6be8222c2be8e70515876affd966ec1d22cc65d", "shasum": "", "mirrors": [ { @@ -468,7 +468,7 @@ "ext-openssl": "*", "php": ">=5.4" }, - "time": "2018-11-13T09:05:11+00:00", + "time": "2018-11-19T13:44:54+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/zoujingli/wechat-developer/AliPay/Bill.php b/vendor/zoujingli/wechat-developer/AliPay/Bill.php index 8817f1d87..4717197fe 100644 --- a/vendor/zoujingli/wechat-developer/AliPay/Bill.php +++ b/vendor/zoujingli/wechat-developer/AliPay/Bill.php @@ -41,6 +41,6 @@ class Bill extends BasicAliPay */ public function apply($options) { - return $this->getResult($options, 'get'); + return $this->getResult($options); } } \ No newline at end of file diff --git a/vendor/zoujingli/wechat-developer/README.md b/vendor/zoujingli/wechat-developer/README.md index a80870993..53f90c472 100644 --- a/vendor/zoujingli/wechat-developer/README.md +++ b/vendor/zoujingli/wechat-developer/README.md @@ -142,6 +142,116 @@ try { } ``` +微信支付 +--- +```php + // 创建接口实例 + $wechat = new \WeChat\Pay($config); + + // 组装参数,可以参考官方商户文档 + $options = [ + 'body' => '测试商品', + 'out_trade_no' => time(), + 'total_fee' => '1', + 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', + 'trade_type' => 'JSAPI', + 'notify_url' => 'http://a.com/text.html', + 'spbill_create_ip' => '127.0.0.1', + ]; + +try { + + // 生成预支付码 + $result = $wechat->createOrder($options); + + // 创建JSAPI参数签名 + $options = $wechat->createParamsForJsApi($result['prepay_id']); + + // @todo 把 $options 传到前端用js发起支付就可以了 + +} catch (Exception $e) { + + // 出错啦,处理下吧 + echo $e->getMessage() . PHP_EOL; + +} +``` +* 更多功能请阅读测试代码或SDK封装源码 + +支付宝支付 +---- +* 支付参数配置(可用沙箱模式) +```php +$config = [ + // 沙箱模式 + 'debug' => true, + // 应用ID + 'appid' => '2016090900468879', + // 支付宝公钥(1行填写) + 'public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtU71NY53UDGY7JNvLYAhsNa+taTF6KthIHJmGgdio9bkqeJGhHk6ttkTKkLqFgwIfgAkHpdKiOv1uZw6gVGZ7TCu5LfHTqKrCd6Uz+N7hxhY+4IwicLgprcV1flXQLmbkJYzFMZqkXGkSgOsR2yXh4LyQZczgk9N456uuzGtRy7MoB4zQy34PLUkkxR6W1B2ftNbLRGXv6tc7p/cmDcrY6K1bSxnGmfRxFSb8lRfhe0V0UM6pKq2SGGSeovrKHN0OLp+Nn5wcULVnFgATXGCENshRlp96piPEBFwneXs19n+sX1jx60FTR7/rME3sW3AHug0fhZ9mSqW4x401WjdnwIDAQAB', + // 支付宝私钥(1行填写) + 'private_key' => 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC3pbN7esinxgjE8uxXAsccgGNKIq+PR1LteNTFOy0fsete43ObQCrzd9DO0zaUeBUzpIOnxrKxez7QoZROZMYrinttFZ/V5rbObEM9E5AR5Tv/Fr4IBywoS8ZtN16Xb+fZmibfU91yq9O2RYSvscncU2qEYmmaTenM0QlUO80ZKqPsM5JkgCNdcYZTUeHclWeyER3dSImNtlSKiSBSSTHthb11fkudjzdiUXua0NKVWyYuAOoDMcpXbD6NJmYqEA/iZ/AxtQt08pv0Mow581GPB0Uop5+qA2hCV85DpagE94a067sKcRui0rtkJzHem9k7xVL+2RoFm1fv3RnUkMwhAgMBAAECggEAAetkddzxrfc+7jgPylUIGb8pyoOUTC4Vqs/BgZI9xYAJksNT2QKRsFvHPfItNt4Ocqy8h4tnIL3GCU43C564B4p6AcjhE85GiN/O0BudPOKlfuQQ9mqExqMMHuYeQfz0cmzPDTSGMwWiv9v4KBH2pyvkCCAzNF6uG+rvawb4/NNVuiI7C8Ku/wYsamtbgjMZVOFFdScYgIw1BgA99RUU/fWBLMnTQkoyowSRb9eSmEUHjt/WQt+/QgKAT2WmuX4RhaGy0qcQLbNaJNKXdJ+PVhQrSiasINNtqYMa8GsQuuKsk3X8TCg9K6/lowivt5ruhyWcP2sx93zY/LGzIHgHcQKBgQDoZlcs9RWxTdGDdtH8kk0J/r+QtMijNzWI0a+t+ZsWOyd3rw+uM/8O4JTNP4Y98TvvxhJXewITbfiuOIbW1mxh8bnO/fcz7+RXZKgPDeoTeNo717tZFZGBEyUdH9M9Inqvht7+hjVDIMCYBDomYebdk3Xqo4mDBjLRdVNGrhGmVQKBgQDKS/MgTMK8Ktfnu1KzwCbn/FfHTOrp1a1t1wWPv9AW0rJPYeaP6lOkgIoO/1odG9qDDhdB6njqM+mKY5Yr3N94PHamHbwJUCmbkqEunCWpGzgcQZ1Q254xk9D7UKq/XUqW2WDqDq80GQeNial+fBc46yelQzokwdA+JdIFKoyinQKBgQCBems9V/rTAtkk1nFdt6EGXZEbLS3PiXXhGXo4gqV+OEzf6H/i/YMwJb2hsK+5GQrcps0XQihA7PctEb9GOMa/tu5fva0ZmaDtc94SLR1p5d4okyQFGPgtIp594HpPSEN0Qb9BrUJFeRz0VP6U3dzDPGHo7V4yyqRLgIN6EIcy1QKBgAqdh6mHPaTAHspDMyjJiYEc5cJIj/8rPkmIQft0FkhMUB0IRyAALNlyAUyeK61hW8sKvz+vPR8VEEk5xpSQp41YpuU6pDZc5YILZLfca8F+8yfQbZ/jll6Foi694efezl4yE/rUQG9cbOAJfEJt4o4TEOaEK5XoMbRBKc8pl22lAoGARTq0qOr9SStihRAy9a+8wi2WEwL4QHcmOjH7iAuJxy5b5TRDSjlk6h+0dnTItiFlTXdfpO8KhWA8EoSJVBZ1kcACQDFgMIA+VM+yXydtzMotOn21W4stfZ4I6dHFiujMsnKpNYVpQh3oCrJf4SeXiQDdiSCodqb1HlKkEc6naHQ=', + // 支付成功通知地址 + 'notify_url' => '', // 可以应用的时候配置哦 + // 网页支付回跳地址 + 'return_url' => '', // 可以应用的时候配置哦 +]; +``` +* 支付宝发起PC网站支付 +```php +// 参考公共参数 https://docs.open.alipay.com/203/107090/ +$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php'; +$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php'; + +try { + + // 实例支付对象 + $pay = We::AliPayWeb($config); + // $pay = new \AliPay\Web($config); + + // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.page.pay + $result = $pay->apply([ + 'out_trade_no' => time(), // 商户订单号 + 'total_amount' => '1', // 支付金额 + 'subject' => '支付订单描述', // 支付订单描述 + ]); + + echo $result; // 直接输出HTML(提交表单跳转) + +} catch (Exception $e) { + + // 异常处理 + echo $e->getMessage(); + +} +``` +* 支付宝发起手机网站支付 +```php +// 参考公共参数 https://docs.open.alipay.com/203/107090/ +$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php'; +$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php'; + +try { + // 实例支付对象 + $pay = We::AliPayWap($config); + // $pay = new \AliPay\Wap($config); + + // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay + $result = $pay->apply([ + 'out_trade_no' => time(), // 商户订单号 + 'total_amount' => '1', // 支付金额 + 'subject' => '支付订单描述', // 支付订单描述 + ]); + echo $result; // 直接输出HTML(提交表单跳转) +} catch (Exception $e) { + + // 异常处理 + echo $e->getMessage(); + +} +``` +* 更多功能请阅读测试代码或SDK封装源码 + 开源协议 ---- * WeChatDeveloper 基于`MIT`协议发布,任何人可以用在任何地方,不受约束 diff --git a/vendor/zoujingli/wechat-developer/We.php b/vendor/zoujingli/wechat-developer/We.php index ca9e066cc..07056763d 100644 --- a/vendor/zoujingli/wechat-developer/We.php +++ b/vendor/zoujingli/wechat-developer/We.php @@ -74,7 +74,7 @@ class We * 定义当前版本 * @var string */ - const VERSION = '1.2.3'; + const VERSION = '1.2.5'; /** * 静态配置 diff --git a/vendor/zoujingli/wechat-developer/WeChat/Contracts/BasicAliPay.php b/vendor/zoujingli/wechat-developer/WeChat/Contracts/BasicAliPay.php index 36140ce2f..360d32198 100644 --- a/vendor/zoujingli/wechat-developer/WeChat/Contracts/BasicAliPay.php +++ b/vendor/zoujingli/wechat-developer/WeChat/Contracts/BasicAliPay.php @@ -15,6 +15,7 @@ namespace WeChat\Contracts; use WeChat\Exceptions\InvalidArgumentException; +use WeChat\Exceptions\InvalidResponseException; /** * 支付宝支付基类 @@ -91,11 +92,11 @@ abstract class BasicAliPay * 查询支付宝订单状态 * @param string $out_trade_no * @return array|boolean - * @throws \WeChat\Exceptions\InvalidResponseException + * @throws InvalidResponseException */ public function query($out_trade_no = '') { - $this->options['method'] = 'alipay.trade.query'; + $this->options->set('method', 'alipay.trade.query'); return $this->getResult(['out_trade_no' => $out_trade_no]); } @@ -104,12 +105,12 @@ abstract class BasicAliPay * @param array|string $options 退款参数或退款商户订单号 * @param null $refund_amount 退款金额 * @return array|boolean - * @throws \WeChat\Exceptions\InvalidResponseException + * @throws InvalidResponseException */ public function refund($options, $refund_amount = null) { if (!is_array($options)) $options = ['out_trade_no' => $options, 'refund_amount' => $refund_amount]; - $this->options['method'] = 'alipay.trade.refund'; + $this->options->set('method', 'alipay.trade.refund'); return $this->getResult($options); } @@ -117,32 +118,51 @@ abstract class BasicAliPay * 关闭支付宝进行中的订单 * @param array|string $options * @return array|boolean - * @throws \WeChat\Exceptions\InvalidResponseException + * @throws InvalidResponseException */ public function close($options) { if (!is_array($options)) $options = ['out_trade_no' => $options]; - $this->options['method'] = 'alipay.trade.close'; + $this->options->set('method', 'alipay.trade.close'); return $this->getResult($options); } /** - * 验证支付宝支付宝通知 - * @param array $data 通知数据 - * @param null $sign 数据签名 - * @param boolean $sync - * @return array|bool + * 获取通知数据 + * @param boolean $needSignType 是否需要sign_type字段 + * @return boolean|array + * @throws InvalidResponseException */ - public function verify($data, $sign = null, $sync = false) + public function notify($needSignType = false) { - if (is_null($this->config->get('public_key'))) { - throw new InvalidArgumentException('Missing Config -- [public_key]'); + $data = $_POST; + if (empty($data) || empty($data['sign'])) { + throw new InvalidResponseException('Illegal push request.', 0, $data); } - $sign = is_null($sign) ? $data['sign'] : $sign; + $string = $this->getSignContent($data, $needSignType); $content = wordwrap($this->config->get('public_key'), 64, "\n", true); - $string = $sync ? json_encode($data) : $this->getSignContent($data, true); $res = "-----BEGIN PUBLIC KEY-----\n{$content}\n-----END PUBLIC KEY-----"; - return openssl_verify($string, base64_decode($sign), $res, OPENSSL_ALGO_SHA256) === 1 ? $data : false; + if (openssl_verify($string, base64_decode($data['sign']), $res, OPENSSL_ALGO_SHA256) !== 1) { + throw new InvalidResponseException('Data signature verification failed.', 0, $data); + } + return $data; + } + + /** + * 验证接口返回的数据签名 + * @param array $data 通知数据 + * @param null|string $sign 数据签名 + * @return array|boolean + * @throws InvalidResponseException + */ + protected function verify($data, $sign) + { + $content = wordwrap($this->config->get('public_key'), 64, "\n", true); + $res = "-----BEGIN PUBLIC KEY-----\n{$content}\n-----END PUBLIC KEY-----"; + if (openssl_verify(json_encode($data, 256), base64_decode($sign), $res, OPENSSL_ALGO_SHA256) !== 1) { + throw new InvalidResponseException('Data signature verification failed.'); + } + return $data; } /** @@ -151,30 +171,28 @@ abstract class BasicAliPay */ protected function getSign() { - if (is_null($this->config->get('private_key'))) { - throw new InvalidArgumentException('Missing Config -- [private_key]'); - } $content = wordwrap($this->config->get('private_key'), 64, "\n", true); $string = "-----BEGIN RSA PRIVATE KEY-----\n{$content}\n-----END RSA PRIVATE KEY-----"; - openssl_sign($this->getSignContent($this->options->get()), $sign, $string, OPENSSL_ALGO_SHA256); + openssl_sign($this->getSignContent($this->options->get(), true), $sign, $string, OPENSSL_ALGO_SHA256); return base64_encode($sign); } /** * 数据签名处理 - * @param array $data - * @param boolean $verify - * @param array $strs + * @param array $data 需要进行签名数据 + * @param boolean $needSignType 是否需要sign_type字段 * @return bool|string */ - private function getSignContent(array $data, $verify = false, $strs = []) + private function getSignContent(array $data, $needSignType = false) { - ksort($data); - foreach ($data as $k => $v) if ($v !== '') { - if ($verify && $k != 'sign' && $k != 'sign_type') array_push($strs, "{$k}={$v}"); - if (!$verify && $v !== '' && !is_null($v) && $k != 'sign' && '@' != substr($v, 0, 1)) array_push($strs, "{$k}={$v}"); + list($attrs,) = [[], ksort($data)]; + if (isset($data['sign'])) unset($data['sign']); + if (empty($needSignType)) unset($data['sign_type']); + foreach ($data as $key => $value) { + if ($value === '' || is_null($value)) continue; + array_push($attrs, "{$key}={$value}"); } - return join('&', $strs); + return join('&', $attrs); } /** @@ -183,15 +201,15 @@ abstract class BasicAliPay */ protected function applyData($options) { - $this->options['biz_content'] = json_encode($options, JSON_UNESCAPED_UNICODE); - $this->options['sign'] = $this->getSign(); + $this->options->set('biz_content', json_encode($this->params->merge($options), 256)); + $this->options->set('sign', $this->getSign()); } /** * 请求接口并验证访问数据 * @param array $options * @return array|boolean - * @throws \WeChat\Exceptions\InvalidResponseException + * @throws InvalidResponseException */ protected function getResult($options) { @@ -199,24 +217,24 @@ abstract class BasicAliPay $method = str_replace('.', '_', $this->options['method']) . '_response'; $data = json_decode(Tools::get($this->gateway, $this->options->get()), true); if (!isset($data[$method]['code']) || $data[$method]['code'] !== '10000') { - throw new \WeChat\Exceptions\InvalidResponseException( + throw new InvalidResponseException( "Error: " . (empty($data[$method]['code']) ? '' : "{$data[$method]['msg']} [{$data[$method]['code']}]\r\n") . (empty($data[$method]['sub_code']) ? '' : "{$data[$method]['sub_msg']} [{$data[$method]['sub_code']}]\r\n"), $data[$method]['code'], $data ); } - return $this->verify($data[$method], $data['sign'], true); + return $this->verify($data[$method], $data['sign']); } /** - * 生成支付html代码 + * 生成支付HTML代码 * @return string */ protected function buildPayHtml() { $html = "<form id='alipaysubmit' name='alipaysubmit' action='{$this->gateway}' method='post'>"; - foreach ($this->params->get() as $key => $value) { + foreach ($this->options->get() as $key => $value) { $value = str_replace("'", ''', $value); $html .= "<input type='hidden' name='{$key}' value='{$value}'/>"; } diff --git a/vendor/zoujingli/wechat-developer/_test/alipay-app.php b/vendor/zoujingli/wechat-developer/_test/alipay-app.php index a905328f8..bbfe18e27 100644 --- a/vendor/zoujingli/wechat-developer/_test/alipay-app.php +++ b/vendor/zoujingli/wechat-developer/_test/alipay-app.php @@ -22,6 +22,7 @@ try { // 实例支付对象 $pay = \We::AliPayApp($config); // $pay = new \AliPay\App($config); + // 请参考(请求参数):https://docs.open.alipay.com/api_1/alipay.trade.app.pay $result = $pay->apply([ 'out_trade_no' => time(), // 商户订单号 @@ -30,7 +31,7 @@ try { ]); echo '<pre>'; var_export($result); -} catch (Exception $e) { +} catch (\Exception $e) { echo $e->getMessage(); } diff --git a/vendor/zoujingli/wechat-developer/_test/alipay-notify.php b/vendor/zoujingli/wechat-developer/_test/alipay-notify.php index 9e9b84bb4..311cb6a98 100644 --- a/vendor/zoujingli/wechat-developer/_test/alipay-notify.php +++ b/vendor/zoujingli/wechat-developer/_test/alipay-notify.php @@ -18,20 +18,20 @@ include "../include.php"; // 2. 准备公众号配置参数 $config = include "./alipay.php"; -// 实例支付对象 -$pay = \We::AliPayApp($config); -// $pay = new \AliPay\App($config); -if ($pay->verify($_POST)) { - file_put_contents('notify.txt', "收到来自支付宝的异步通知\r\n", FILE_APPEND); - file_put_contents('notify.txt', '订单号:' . $_POST['out_trade_no'] . "\r\n", FILE_APPEND); - file_put_contents('notify.txt', '订单金额:' . $_POST['total_amount'] . "\r\n\r\n", FILE_APPEND); -} else { - file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND); -} - -// 下面是支付通知处理 -$pay = new \AliPay\App($config); -$notify = $pay->verify($_POST); -if (in_array($notify['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) { - // @todo 更新订单状态,支付完成 +try { + // 实例支付对象 + $pay = \We::AliPayApp($config); + // $pay = new \AliPay\App($config); + $data = $pay->notify(); + if (in_array($data['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) { + // @todo 更新订单状态,支付完成 + file_put_contents('notify.txt', "收到来自支付宝的异步通知\r\n", FILE_APPEND); + file_put_contents('notify.txt', '订单号:' . $data['out_trade_no'] . "\r\n", FILE_APPEND); + file_put_contents('notify.txt', '订单金额:' . $data['total_amount'] . "\r\n\r\n", FILE_APPEND); + } else { + file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND); + } +} catch (\Exception $e) { + // 异常处理 + echo $e->getMessage(); } diff --git a/vendor/zoujingli/wechat-developer/_test/alipay-wap.php b/vendor/zoujingli/wechat-developer/_test/alipay-wap.php index 8a0aab346..3b63833e7 100644 --- a/vendor/zoujingli/wechat-developer/_test/alipay-wap.php +++ b/vendor/zoujingli/wechat-developer/_test/alipay-wap.php @@ -31,8 +31,7 @@ try { 'total_amount' => '1', // 支付金额 'subject' => '支付订单描述', // 支付订单描述 ]); - echo '<pre>'; - var_export($result); + echo $result; } catch (Exception $e) { echo $e->getMessage(); } diff --git a/vendor/zoujingli/wechat-developer/_test/alipay-web.php b/vendor/zoujingli/wechat-developer/_test/alipay-web.php index 2225f11f6..e0e3b86c8 100644 --- a/vendor/zoujingli/wechat-developer/_test/alipay-web.php +++ b/vendor/zoujingli/wechat-developer/_test/alipay-web.php @@ -32,8 +32,7 @@ try { 'total_amount' => '1', // 支付金额 'subject' => '支付订单描述', // 支付订单描述 ]); - echo '<pre>'; - var_export($result); + echo $result; } catch (Exception $e) { echo $e->getMessage(); } diff --git a/vendor/zoujingli/wechat-developer/_test/alipay.php b/vendor/zoujingli/wechat-developer/_test/alipay.php index f4fe48a0c..468650725 100644 --- a/vendor/zoujingli/wechat-developer/_test/alipay.php +++ b/vendor/zoujingli/wechat-developer/_test/alipay.php @@ -1,6 +1,19 @@ <?php -// 沙箱模式 + +// +---------------------------------------------------------------------- +// | WeChatDeveloper +// +---------------------------------------------------------------------- +// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] +// +---------------------------------------------------------------------- +// | 官方网站: http://think.ctolog.com +// +---------------------------------------------------------------------- +// | 开源协议 ( https://mit-license.org ) +// +---------------------------------------------------------------------- +// | github开源项目:https://github.com/zoujingli/WeChatDeveloper +// +---------------------------------------------------------------------- + return [ + // 沙箱模式 'debug' => true, // 应用ID 'appid' => '2016090900468879', diff --git a/vendor/zoujingli/wechat-developer/_test/config.php b/vendor/zoujingli/wechat-developer/_test/config.php index 687b2dd32..010618cda 100644 --- a/vendor/zoujingli/wechat-developer/_test/config.php +++ b/vendor/zoujingli/wechat-developer/_test/config.php @@ -15,7 +15,7 @@ return [ 'token' => 'test', 'appid' => 'wx60a43dd8161666d4', - 'appsecret' => '71308e96a204296c57d7cd4b21b883e8', + 'appsecret' => 'b4e28746f1bd73b5c6684f5e01883c36', 'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5', // 配置商户支付参数 'mch_id' => "1332187001", diff --git a/vendor/zoujingli/wechat-developer/_test/wechat-user-get.php b/vendor/zoujingli/wechat-developer/_test/wechat-user-get.php index 5517afa61..ad94e3ad9 100644 --- a/vendor/zoujingli/wechat-developer/_test/wechat-user-get.php +++ b/vendor/zoujingli/wechat-developer/_test/wechat-user-get.php @@ -26,6 +26,7 @@ try { // 4. 获取用户列表 $result = $wechat->getUserList(); + echo '<pre>'; var_export($result); // 5. 批量获取用户资料