微信h5支付

首先从官方网站下载demo: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1

这里下载的是微信公众号支付所使用的demo

下载以后 还需要改动一些地方,你可以到如下地址查看 http://www.upwqy.com/soft/check/12.html 也可以下载demo

交待一下开发环境

window  

thinkphp5 

thinkcmf5

原文:http://www.upwqy.com/details/222.html

具体代码如下 

ini_set('date.timezone', 'Asia/Shanghai');
Loader::import('paywx.lib.WxPay', EXTEND_PATH, '.Api.php');

  模型(model)中

public  function pay($subject,$out_trade_no,$total_amount){
    $input = new WxPayUnifiedOrder();
    $input->SetBody($subject);
    $input->SetOut_trade_no($out_trade_no);
    $input->SetTotal_fee($total_amount * 100);
    $input->SetNotify_url("回调地址");
    $input->SetTrade_type("MWEB");

    $scene_info = '{"h5_info":{"type":"Wap","wap_url":"域名","wap_name":"企业名称"}}';

    $input->SetValues("scene_info",$scene_info);


    $wxOrder = WxPayApi::unifiedOrder($input);
    if ($wxOrder['return_code'] != 'SUCCESS' ||
        $wxOrder['result_code'] != 'SUCCESS'
    )
    {
        Log::record($wxOrder, 'error');
        Log::record('获取预支付订单失败', 'error');
    }

    return $wxOrder;
}
 

在控制器中 有些数据 改为自己代码中的数据  

$wxpay = new WxPayService();
$result = $wxpay->pay($order['snap_name'],$order_no,'0.01');        
if ($result['result_code'] == 'SUCCESS' && $result['return_code'] == 'SUCCESS') {

    $url = $result['mweb_url']."&redirect_url=".urlencode("支付完需要返回的链接 http://www.upwqy.com/soft/check/12.html");
    $this->success('获取成功',null,['url'=>$url]);
}else{
    $this->error($result['return_msg']);
}

前端代码:

$.ajax({
    type:'post',
    dataType:'json',
    data:{},
    timeout:10000,
    url:"{:url('Pay/wxPay')}",
    success:function (res) {

        if(res.code){
            window.location.href = res.data.url;
        }
    }
});
原文地址:https://www.cnblogs.com/wqy415/p/9027854.html