微擎模块开发-微信小程序付功能详解(tpwe模块同理)

最近在在做微擎模块转tpwe模块开发,需要了解微擎支付的流程,一般小程序前端请求对应模块下面  wxapp.php 指定的方法,然后再指定方法里面调用微擎本身自带的$pay_params = $this->pay($order);方法返回支付签名即可。所以tpwe做的时候最重要是做pay方法即可!

pay.wxml


	pay: function (orderId) {
		var that = this
		app.util.request({
			'url': 'entry/wxapp/pay', //调用模块里面wxapp.php中的doPagePay方法获取支付参数
			data: {
				orderid: orderId  //订单id
			},
			'cachetime': '0',
			success(res) {
				if (res.data && res.data.data && !res.data.errno) {
					//发起支付
					wx.requestPayment({
						'timeStamp': res.data.data.timeStamp,
						'nonceStr': res.data.data.nonceStr,
						'package': res.data.data.package,
						'signType': 'MD5',
						'paySign': res.data.data.paySign,
						'success': function (res) {
						
							//订单支付成功,修改订单状态至代发货
							app.util.request({
								url: 'entry/wxapp/orderstatus',//调用模块里面wxapp.php中的doPagePay方法获取支付参数
								data: {
									
									orderId: orderId
								},
								success(res) {
									that.setData({

									})
								}
							})
							wx.showToast({
								title: '支付成功',
								icon: 'success',
								duration: 2000
							})
							setTimeout(function () {
								wx.navigateTo({
									url: 'payresult/index?id='+orderId,
								})
							}, 2000)
						},
						'fail': function (res) {
							console.log('支付失败')
						}
					})
				}
			},
			fail(res) {
				wx.showModal({
					title: '系统提示',
					content: res.data.message ? res.data.message : '错误',
					showCancel: false,
					success: function (res) {
						if (res.confirm) {
							backApp()
						}
					}
				})
			}
		})
	},

wxapp.php

// 调用微信支付接口
	public function doPagePay() {
		global $_GPC, $_W;
        //获取订单号,保证在业务模块中唯一即可
		$orderid = $_GPC['orderid'];
		//查询
        $order = pdo_get('order',array('orderid'=>$orderid));
        //构造支付参数
		$order = array(
			'tid' => $orderid,
            'user' => $_W['openid'], //用户OPENID
            'fee' => floatval($order['price']), //金额
            'title' => 'tpwe系统',
        );
        //生成支付参数,返回给小程序端
		$pay_params = $this->pay($order);
		if (is_error($pay_params)) {
			return $this->result(1, '支付失败,请重试');
		}
		return $this->result(0, '', $pay_params);
	}

                                                                                                                    承接微擎模块开发,微擎模块独立 微信:tpwe8888

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会写代码的程序猿-蜀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值