php 小程序支付 退款,微擎小程序支付功能+退款功能

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');

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值