• 小程序学习-支付以及调起摄像头扫描二维码


    前台流程是
    1,给后台传一个code(必传)和后台需要的参数后台返回我参数
    2,成功后我拉起支付吧这几个返回参数在传给微信端 然后监听结果

    // 用户点击我要支付按钮后
    wx.login({
          success: function (res) {
            if (res.code) {
              //发起网络请求
              wx.request({
                url: 这里是后台接口, //你需要给后台传一个code
                method: 'GET',
                data: {
                  code: res.code  //请求wx.login成功后会返回一个code
                },
                success: function (r) {  // 成功后  后台返回参数  timeStamp,nonceStr,package,paySign,appid。(有的还会返回其他参数,左边的这几个参数是必须返回的)
                  var _res = r.data.data  //   太长了把r下面的data给_res这个变量
                  wx.requestPayment({    //调起支付               
                    'timeStamp': _r.timeStamp,  // 必填 时间戳从1970年1月1日00:00:00至今的秒数,即当前的              
                    'nonceStr': _r.nonceStr,  // 必填 随机字符串,长度为32个字符以下。
                    'package': _r.package,  // 必填  统一下单接口返回的 prepay_id 参数值
                    'signType': 'MD5',  // 必填 签名算法,暂支持 MD5
                    'paySign': _r.paySign, // 必填 签名
                    'success': function (res) { // 接口调用成功的回调函数
                      console.log(res);
                    },
                    'fail': function (res) { // 接口调用失败的回调函数
                      console.log('fail:' + JSON.stringify(res));
                    }
                  })
                },
                fail: function (err) {
                  console.log(err)
                }
              })
            } else {
              console.log('获取用户登录态失败!' + res.errMsg)
            }
          }
        })
     1 扫码
     2 // 允许从相机和相册扫码
     3 wx.scanCode({
     4   success(res) {
     5     console.log(res)
     6   }
     7 })
     8 // 只允许从相机扫码
     9 wx.scanCode({
    10   onlyFromCamera: true,
    11   success(res) {
    12     console.log(res)
    13   }
    14 })

    // 转载

  • 相关阅读:
    安全预警-防范新型勒索软件“BlackRouter”
    线程入门
    线程状态
    支付开发总结
    springboot处理date参数
    函数接口
    Excel通用类工具(一)
    Excel通用类工具(二)
    spring bean生命周期
    springboot整合netty(二)
  • 原文地址:https://www.cnblogs.com/Alitar/p/11418624.html
Copyright © 2020-2023  润新知