THINKPHP Yansongda 微信H5支付,公众号支付

46 篇文章 0 订阅
9 篇文章 0 订阅

说的无益,看代码就行了  更多支付方式请到https://pay.yansongda.cn/docs/v2/

1. 微信H5支付

            $config = [
                'appid' => 'wxb3fxxxxxxxxxxx', // APP APPID
                'app_id' => 'appid', // 公众号 APPID
                'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
                'mch_id' => 'merchant',
                'key' => 'secretkey',
                'notify_url' => 'wechatNotify',
                'cert_client' => './cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到
                'cert_key' => './cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到
                'log' => [ // optional
                    'file' => LOG_PATH.'logs/wechat.log',
                    'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
                    'type' => 'single', // optional, 可选 daily.
                    'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
                ],
                'http' => [ // optional
                    'timeout' => 5.0,
                    'connect_timeout' => 5.0,
                    // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
                ],
                // 'mode' => 'dev',
            ];

            $order = [
                'out_trade_no' => $number,
                'body' => '支付测试',
                'total_fee'      => intval(0.01 * 100)
            ];
            
            $pay = Pay::wechat($config)->wap($order); // (移动端H5支付)
            return redirect($pay->getTargetUrl());exit;  // 获取返回的链接直接跳转

2. 微信公众号支付

$config = [
                'appid' => 'wxb3fxxxxxxxxxxx', // APP APPID
                'app_id' => 'appid', // 公众号 APPID
                'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
                'mch_id' => 'merchant',
                'key' => 'secretkey',
                'notify_url' => 'wechatNotify',
                'cert_client' => './cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到
                'cert_key' => './cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到
                'log' => [ // optional
                    'file' => LOG_PATH.'logs/wechat.log',
                    'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
                    'type' => 'single', // optional, 可选 daily.
                    'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
                ],
                'http' => [ // optional
                    'timeout' => 5.0,
                    'connect_timeout' => 5.0,
                    // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
                ],
                // 'mode' => 'dev',
            ];
  
            $order = [
                'out_trade_no' => $number,
                'body' => '充值支付',
                'total_fee'      => intval(0.01 * 100)
            ];

            $order['openid'] = 'openid'; // 微信openid
            $result = Pay::wechat($config)->mp($order);

            $resData = [   //返回信息给前台 ,前台调起来微信支付
                'appId' => $result->appId,
                'timeStamp' => $result->timeStamp,
                'nonceStr' => $result->nonceStr,
                'package' => $result->package,
                'signType' => $result->signType,
                'paySign' => $result->paySign,
            ];       //{"appId":"wx","timeStamp":"16103","nonceStr":"oOSji","package":"prepay_id=wx085123","signType":"MD5","paySign":"589B82F"}  前端调用的格式
                $jsApiParameters = json_encode($resData); // 转成功json格式页面直接调用即可
                $this->assign('jsApiParameters', $jsApiParameters);
                return $this->fetch(':wechatpay');
            

公众号支付需要页面调起,页面代码

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <title>微信安全支付</title>
    <script type="text/javascript">
        //调用微信JS api 支付
        function jsApiCall()
        {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                {$jsApiParameters},
                function(res){
                    // alert(res.err_code+res.err_desc+res.err_msg);
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        window.location.href = "支付成功跳转";
                    } else if(res.err_msg == "get_brand_wcpay_request:fail" ) {  //支付失
                        window.location.href = "失败跳转";
                    }
                }
            );
        }
        //function callpay()
        window.onload = function ()
        {
            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            }else{
                jsApiCall();
            }
        }
    </script>
</head>
<body>
<?php if(!strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')){?>
<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>
<?php }?>
</body>
</html>

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值