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


1,要使用微擎特定的小程序框架

https://gitee.com/we7coreteam/wxapp

2,必須正確的配置siteinfo

https://www.kancloud.cn/qq188872170/xcx/673488

var siteinfo = {
"m": 'yhjd_fhjs',
"uniacid": "2",
"acid": "2",
"multiid": "0",
"version": "1.01",
"siteroot": "https://02.zcwlkj.cn/app/index.php",
'method_design': '3'
};
module.exports = siteinfo;
 
3,發起支付的頁面,必須有m參數
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這兩個證書
 
  1. //首先load模塊函數
  2. load()->model('refund');
  3. //創建退款訂單
  4. //$tid 模塊內訂單id
  5. //$module 需要退款的模塊
  6. //$fee 退款金額
  7. //$reason 退款原因
  8. //成功返回退款單id,失敗返回error結構錯誤
  9. $refund_id = refund_create_order($tid, $module, $fee, $reason);
  10. if (is_error($refund_id)) {
  11. itoast($refund_id['message'], referer(), 'error');
  12. }
  13. //發起退款
  14. $refund_result = refund($refund_id);
  15. if (is_error($refund_result)) {
  16. itoast($refund_result['message'], referer(), 'error');
  17. } else {
  18. pdo_update('core_refundlog', array('status' => 1), array('id' => $refund_id));
  19. //XXX(這里繼續寫自己的其他邏輯)
  20. itoast('退款成功', referer(), 'info');
  21. }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM