700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > php微信wap页面支付 微信 手机网站 h5 wap浏览器 支付

php微信wap页面支付 微信 手机网站 h5 wap浏览器 支付

时间:2018-12-02 21:43:14

相关推荐

php微信wap页面支付 微信 手机网站 h5 wap浏览器 支付

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

交待一下开发环境

window

thinkphp5

thinkcmf5

具体代码如下

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

模型(model)中

public functionpay($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=newWxPayService();$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("支付完需要返回的链接 /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;

}

}

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。