From 2f91b6082d638f266a08cf13f024037d3fde141a Mon Sep 17 00:00:00 2001 From: Anyon Date: Thu, 3 May 2018 14:50:43 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E5=A2=9E=E5=8A=A0=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=94=AF=E4=BB=98=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Index.php | 46 ++++++++++++++++++++++++++ config/wechat.php | 3 ++ 2 files changed, 49 insertions(+) diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 9398d3aa4..5bff821d5 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -14,7 +14,9 @@ namespace app\index\controller; +use service\WechatService; use think\Controller; +use WeChat\Pay; /** * 应用入口控制器 @@ -28,4 +30,48 @@ class Index extends Controller $this->redirect('@admin/login'); } + public function pay() + { + $wechat = new Pay(config('wechat.')); + $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', + ]; + // 生成预支付码 + $result = $wechat->createOrder($options); + // 创建JSAPI参数签名 + $options = $wechat->createParamsForJsApi($result['prepay_id']); + $optionJSON = json_encode($options, JSON_UNESCAPED_UNICODE); + $configJSON = json_encode(WechatService::webJsSDK(), JSON_UNESCAPED_UNICODE); + + echo '
';
+        echo "\n--- 创建预支付码 ---\n";
+        var_export($result);
+        echo '
'; + + echo '
';
+        echo "\n\n--- JSAPI 及 H5 参数 ---\n";
+        var_export($options);
+        echo '
'; + echo ""; + echo " + + "; + } + } diff --git a/config/wechat.php b/config/wechat.php index 504eacd0f..430e611a9 100644 --- a/config/wechat.php +++ b/config/wechat.php @@ -14,4 +14,7 @@ return [ 'service_url' => 'https://service.thinkadmin.top', + 'appid' => 'wx60a43dd8161666d4', + 'mch_id' => '1332187001', + 'mch_key' => 'A82DC5BD1F3359081049C568D8502BC5', ]; \ No newline at end of file