From 84465273f82f906056f1898ced605c50cea68e98 Mon Sep 17 00:00:00 2001 From: hejiangbo <2309689757@qq.com> Date: Sun, 10 Nov 2024 23:21:50 +0800 Subject: [PATCH] =?UTF-8?q?11.10=20=E7=BB=91=E5=AE=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/request/request.js | 2 +- sheep/platform/pay.js | 49 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/common/request/request.js b/common/request/request.js index 19011f6..aa25a46 100644 --- a/common/request/request.js +++ b/common/request/request.js @@ -3,7 +3,7 @@ const request = (options) => { // 例如: return new Promise((resolve, reject) => { let token = uni.getStorageSync('token') - uni.request({ + wx.request({ url: options.url || '', method: options.method || 'GET', data: options.data || {}, diff --git a/sheep/platform/pay.js b/sheep/platform/pay.js index ed5c0c7..8d418a2 100644 --- a/sheep/platform/pay.js +++ b/sheep/platform/pay.js @@ -7,6 +7,7 @@ import { } from '@/sheep/helper'; import PayOrderApi from '@/sheep/api/pay/order'; import wechat from '@/sheep/platform/provider/wechat/index.js'; +import SocialApi from '@/sheep/api/member/social'; /** * 支付 * @@ -331,14 +332,58 @@ export default class SheepPay { uni.showModal({ title: '微信支付', content: '请先绑定微信再使用微信支付', - success: function(res) { + success: function (res) { if (res.confirm) { - sheep.$platform.useProvider('wechat').bind(); + // sheep.$platform.useProvider('wechat').bind(); + return new Promise(async (resolve, reject) => { + // 1. 获得微信 code + const codeResult = await uni.login(); + console.log(codeResult, 'codeResult') + if (codeResult.errMsg !== 'login:ok') { + return resolve(false); + } else { + // 2. 绑定账号 + const bindResult = await SocialApi.socialBind(34, + codeResult.code, 'default'); + console.log(bindResult, 'bindResult') + if (bindResult.code === 0) { + // setOpenid(bindResult.data); + uni.setStorageSync('openid', bindResult.data); + return resolve(true); + } else { + return resolve(false); + } + } + }); } }, }); } + async bind() { + return new Promise(async (resolve, reject) => { + // 1. 获得微信 code + const codeResult = await uni.login(); + console.log(codeResult, 'codeResult') + if (codeResult.errMsg !== 'login:ok') { + return resolve(false); + } else { + // 2. 绑定账号 + const bindResult = await SocialApi.socialBind(socialType, codeResult.code, 'default'); + console.log(bindResult, 'bindResult') + if (bindResult.code === 0) { + // setOpenid(bindResult.data); + uni.setStorageSync('openid', bindResult.data); + return resolve(true); + } else { + return resolve(false); + } + } + }); + }; + + + } export function getPayMethods(channels) {