appInfo.util.request({
'url': 'entry/wxapp/pay', //调用wxapp.php中的doPagePay方法获取支付参数
data: {
orderid: params.ordertid,
fee: params.fee,
openid: appInfo.globalData.openid,
m: appInfo.siteInfo.m
},
'cachetime': '0',
success(res) {
console.log(res);
}
});
4,PHP端生成支付参数——————wxapp.php文件就是专门用来写这个小程序支付逻辑的
class We7WxappDemoModuleWxapp extends WeModuleWxapp {
public function doPagePay() {
global $_GPC, $_W;
//获取订单号,保证在业务模块中唯一即可
$orderid = intval($_GPC['orderid']);
//构造支付参数
$order = array(
'tid' => $orderid,
'user' => $_W['openid'], //用户OPENID
'fee' => floatval($fee), //金额
'title' => '小程序支付示例',
);
//生成支付参数,返回给小程序端
$pay_params = $this->pay($order);
if (is_error($pay_params)) {
return $this->result(1, '支付失败,请重试');
}
return $this->result(0, '', $pay_params);
}
}
小程序端发起支付
app.util.request({
'url': 'entry/wxapp/pay', //调用wxapp.php中的doPagePay方法获取支付参数
data: {
orderid: options.orderid,
},
'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) {
//执行支付成功提示
},
'fail': function (res) {
backApp()
}
})
}
},
fail(res) {
wx.showModal({
title: '系统提示',
content: res.data.message ? res.data.message : '错误',
showCancel: false,
success: function (res) {
if (res.confirm) {
backApp()
}
}
})
}
})
验证支付结果
和模块一样,验证代码写在 payResult() 函数中即可。
微擎退款功能——
1,微擎的支付订单存储在ims_core_paylog中,
2,退款订单存储在ims_core_refundlog中
3,支付和退款,都必须配置参数,退款要配置文件
证书:
使用微信退款功能需要上传双向证书。
证书下载方式:
微信商户平台(pay.weixin.qq.com)-->账户中心-->账户设置-->API安全-->证书下载。
我们仅用到apiclient_cert.pem 和 apiclient_key.pem这两个证书
//首先load模块函数
load()->model('refund');
//创建退款订单
//$tid 模块内订单id
//$module 需要退款的模块
//$fee 退款金额
//$reason 退款原因
//成功返回退款单id,失败返回error结构错误
$refund_id =refund_create_order($tid,$module,$fee,$reason);
if(is_error($refund_id)){
itoast($refund_id['message'],referer(),'error');
}
//发起退款
$refund_result =refund($refund_id);
if(is_error($refund_result)){
itoast($refund_result['message'],referer(),'error');
}else{
pdo_update('core_refundlog',array('status'=>1),array('id'=>$refund_id));
//XXX(这里继续写自己的其他逻辑)
itoast('退款成功',referer(),'info');
}