- app的H5支付,安卓正常支付,但是苹果支付却报商家存在未配置的参数,请联系商家解决
doWxPay(param, orderId) { uni.showLoading({ title: '正在请求支付' }); let base = param let url = encodeURIComponent(config.webUrl + '/#/pages/cart/switchOrder/index?message=支付成功&orderId=' + orderId) location.href = base.mweb_url + `&redirect_url=${url}` } [图片]
2021-01-21 - 小程序登录的逻辑和获取openId和session_key的过程?
登录的逻辑是这样的 wx.checkSession验证session_key是否过去 => wx.login登录获取code => wx.getSetting获取用户当前设置 => wx.getUserInfo获取用户的信息 => 获取用户的openid和session_key 看一下哪部分可以不需要,省去的 附上我的代码app.js [代码]//app.js[代码][代码]let AppId = [代码][代码]'wxb56d****f9f4d'[代码][代码];[代码][代码]let AppSecret = [代码][代码]'51fafc123******a7c29e3cc01'[代码][代码];[代码][代码]let LoginSessionKey = [代码][代码]'LoginSessionKey'[代码][代码];[代码][代码]App({[代码][代码] [代码][代码]// 顺序: wx.checkSession验证session_key是否过去 => wx.login登录获取code => wx.getSetting获取用户当前设置 => wx.getUserInfo获取用户的信息 => 获取用户的openid和session_key[代码][代码] [代码][代码]onLaunch: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]let self = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.checkSession({[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](){[代码][代码] [代码][代码]//session_key 未过期,并且在本生命周期一直有效[代码][代码] [代码][代码]console.log([代码][代码]'session_key 未过期'[代码][代码]);[代码][代码] [代码][代码]if[代码] [代码](wx.getStorageSync(LoginSessionKey)) [代码][代码]return[代码][代码];[代码][代码] [代码][代码]self.getSetting();[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码][代码](){[代码][代码] [代码][代码]// session_key 已经失效,需要重新执行登录流程[代码][代码] [代码][代码]console.log([代码][代码]'session_key 已经失效'[代码][代码]);[代码][代码] [代码][代码]self.getSetting();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]getSetting() {[代码][代码] [代码][代码]let self = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]self.getLogin().then((code)=> {[代码][代码] [代码][代码]wx.getSetting({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]if[代码] [代码](res.authSetting[[代码][代码]'scope.userInfo'[代码][代码]]) {[代码][代码] [代码][代码]wx.getUserInfo({[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](userInfo) {[代码][代码] [代码][代码]self.globalData.userInfo = userInfo;[代码][代码] [代码][代码]self.getJsCode(code)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]getLogin() {[代码][代码] [代码][代码]return[代码] [代码]new[代码] [代码]Promise((resolve, reject)=> {[代码][代码] [代码][代码]wx.login({[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](params) {[代码][代码] [代码][代码]let code = params.code;[代码][代码] [代码][代码]if[代码] [代码](code) {[代码][代码] [代码][代码]wx.showToast({[代码][代码] [代码][代码]title: [代码][代码]'正在登录...'[代码][代码],[代码][代码] [代码][代码]icon: [代码][代码]'loading'[代码][代码],[代码][代码] [代码][代码]duration: 10000[代码][代码] [代码][代码]});[代码][代码] [代码][代码]resolve(code)[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]reject(params.errMsg)[代码][代码] [代码][代码]console.log([代码][代码]'获取用户登录态失败!'[代码] [代码]+ params.errMsg)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]getJsCode(code) {[代码][代码] [代码][代码]wx.request({[代码][代码] [代码][代码]url: [代码][代码]'https://api.weixin.qq.com/sns/jscode2session'[代码][代码],[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]appid: AppId,[代码][代码] [代码][代码]secret: AppSecret,[代码][代码] [代码][代码]js_code: code,[代码][代码] [代码][代码]grant_type: [代码][代码]'authorization_code'[代码][代码] [代码][代码]},[代码][代码] [代码][代码]method: [代码][代码]'GET'[代码][代码],[代码][代码] [代码][代码]header: {[代码][代码] [代码][代码]'content-type'[代码][代码]: [代码][代码]'application/json'[代码][代码] [代码][代码]}, [代码][代码]// 设置请求的 header[代码][代码] [代码][代码]success: (res)=> {[代码][代码] [代码][代码]console.log(res.data);[代码][代码] [代码][代码]if[代码] [代码](res.errcode && res.errcode == 40029 && res.statusCode !== 200) {[代码][代码] [代码][代码]wx.showToast({[代码][代码] [代码][代码]title: [代码][代码]'Code无效, 稍后重试'[代码][代码],[代码][代码] [代码][代码]duration: 10000[代码][代码] [代码][代码]});[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]let openid = res.data.openid,[代码][代码] [代码][代码]session_key = res.data.session_key;[代码][代码] [代码][代码]wx.setStorageSync(LoginSessionKey, {openid,session_key})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]wx.showToast({[代码][代码] [代码][代码]title: [代码][代码]'请求失败, 稍后重试'[代码][代码],[代码][代码] [代码][代码]duration: 10000[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]wx.hideToast();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]globalData: {[代码][代码] [代码][代码]user: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]userInfo: [代码][代码]null[代码][代码] [代码][代码]}[代码][代码]})[代码] 求大神帮我分析一下,此步骤是否合理?
2018-04-19