diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 2a95384d5..ca70a9d5b 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -14,9 +14,7 @@ namespace app\index\controller; -use service\WechatService; use think\Controller; -use WeChat\Pay; /** * 应用入口控制器 @@ -29,52 +27,4 @@ class Index extends Controller { $this->redirect('@admin/login'); } - - public function pay() - { - $wechat = new Pay(config('wechat.')); - $openid = WechatService::webOauth($this->request->url(true), 0)['openid']; - $options = [ - 'body' => '测试商品', - 'out_trade_no' => time(), - 'total_fee' => '1', - 'openid' => $openid, - '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); - // JSSDK 签名配置 - $configJSON = json_encode(WechatService::webJsSDK(), JSON_UNESCAPED_UNICODE); - - echo '
';
-        echo "当前用户OPENID: {$openid}";
-        echo "\n--- 创建预支付码 ---\n";
-        var_export($result);
-        echo '
'; - - echo '
';
-        echo "\n\n--- JSAPI 及 H5 参数 ---\n";
-        var_export($options);
-        echo '
'; - echo ""; - echo " - - "; - } - } diff --git a/application/store/controller/wechat/Demo.php b/application/store/controller/wechat/Demo.php new file mode 100644 index 000000000..710fb9462 --- /dev/null +++ b/application/store/controller/wechat/Demo.php @@ -0,0 +1,81 @@ +url(true), 0)['openid']; + $options = [ + 'body' => '测试商品', + 'out_trade_no' => time(), + 'total_fee' => '1', + 'openid' => $openid, + '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); + // JSSDK 签名配置 + $configJSON = json_encode(WechatService::webJsSDK(), JSON_UNESCAPED_UNICODE); + + echo '
';
+        echo "当前用户OPENID: {$openid}";
+        echo "\n--- 创建预支付码 ---\n";
+        var_export($result);
+        echo '
'; + + echo '
';
+        echo "\n\n--- JSAPI 及 H5 参数 ---\n";
+        var_export($options);
+        echo '
'; + echo ""; + echo " + + "; + } + +} \ No newline at end of file diff --git a/application/store/controller/wechat/Index.php b/application/store/controller/wechat/Index.php index 77efed4f9..b1dffc627 100644 --- a/application/store/controller/wechat/Index.php +++ b/application/store/controller/wechat/Index.php @@ -1,10 +1,16 @@