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