• 注册
  • 查看作者
  • 微擎小程序支付微擎小程序支付

    文档:http://s.w7.cc/index.php?c=wiki&do=view&id=1&list=832
    第一步:小程序后台绑定商户号
    第二步:微擎后台–>进入小程序管理–>支付参数配置(商户号和秘钥)
    第三步:php端生成支付参数

    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()
                    }
                }
            })
        }
    })
    
  • 0
  • 0
  • 0
  • 35
  • 请登录之后再进行评论

    登录

    捐助

    请在小工具里添加二维码

  • 任务
  • 发布
  • 单栏布局 侧栏位置: