uniapp项目APP接入微信支付

1.获取到需要的前置条件
2.在app模块配置中打开微信支付并填入appid
3.tp框架中引入esaywechat(我用的4.0)

config = [ 'app_id' => 'xxx', 'mch_id' => 'xxx', 'key' => 'xxx', 'notify_url' => '回调地址, ];app = Factory::payment(config);result2 = app->order->unify([ 'body' => '11111111', 'out_trade_no' => 'xxxx', 'total_fee' => 1, 'notify_url' => 'xxxx', // 支付结果通知网址,如果不设置则会使用配置里的默认地址 // 'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型 ]); 5.回调 //微信支付回调函数 public function wx_notify(json){
obj = json_decode(json, true);
if(out_trade_no =obj['out_trade_no']){ //123123 回调
//订单
find = Db::name('order')->where('order_num',out_trade_no)->find();
if(find &&find['status'] == '1'){
if(find['is_visit'] == 1) { Db::name('order')->where('order_num',out_trade_no)->update(['status' => '4', 'pay_time' => time()]);
}else {
Db::name('order')->where('order_num', out_trade_no)->update(['status' => '3', 'pay_time' => time()]); } } } } 7.前端相应代码 _self.Api.dajax('order/createCarRecord',all,'post',res=>{
if(res.status) {
console.log(res.data)
uni.request({
url:支付请求的路径,
data:{
total:res.data.price,
subject:'订单',
out_trade_no:res.data.order_num
},
method:'GET',
success(res) {
console.log(res)
uni.requestPayment({
provider: 'wxpay',
orderInfo: res.data,
success: function(res) {
_self.$common.showMsg('支付成功')
setTimeout(()=>{
uni.reLaunch({
url:'../index/index'
})
},500)
},
fail: function(err) {
// app.msg('', JSON.stringify(err))
console.log('fail:' + JSON.stringify(err));
},
complete: () => {

                                        }
                                    });
                                                
                                }
                            })
                        }
                    })
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容