旅游教育出版社-数字教材移动端
litian
2025-06-30 a874dd8b06b90ea5157e9809fcdf5a38ad115dde
src/assets/js/weChat/weChat.js
@@ -1,18 +1,17 @@
import {
  appRefCode
} from "@/assets/js/config";
import { appRefCode } from "@/assets/js/config";
import service from "@/plugin/axios";
let wxAppId = "wxd2941f9abd7ba978"; // 微信AppId
let WeChat = {
  getCode: (state) => {
  getCode: state => {
    // 调起授权,获取code。注意:每次调用时先清除已储存的token,避免后续跳转监听到旧的token,一直401
    const url = window.location.href;
    console.log(window.location.href, 1);
    const routeCode = url.split("#")[1];
    if (routeCode == 'weChatLogin' || routeCode == '/selectLoginMethod') {
    if (routeCode == "/weChatLogin" || routeCode == "/selectLoginMethod") {
      window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${wxAppId}&redirect_uri=${encodeURIComponent(
        'https://www.tepcb.com/mobile/textbooks/#/personalCenter'
        "https://www.tepcb.com/mobile/textbooks/#/personalCenter"
      )}&response_type=code&scope=snsapi_userinfo&state=${state}`;
    } else {
      window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${wxAppId}&redirect_uri=${encodeURIComponent(
@@ -92,7 +91,8 @@
    const resData = JSON.parse(data);
    // eslint-disable-next-line
    WeixinJSBridge.invoke(
      "getBrandWCPayRequest", {
      "getBrandWCPayRequest",
      {
        appId: resData.appId, // 公众号名称,由商户传入
        timeStamp: resData.timeStamp, // 时间戳
        nonceStr: resData.nonceStr, // 随机串
@@ -100,7 +100,7 @@
        signType: resData.signType, // 微信签名方式
        paySign: resData.paySign // 微信签名
      },
      function (res) {
      function(res) {
        // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
        if (res.err_msg == "get_brand_wcpay_request:ok") {
          // 支付成功
@@ -121,7 +121,7 @@
            callback(flag, res.errMsg || res.err_msg);
          }
        }
      }
      }
    );
  }
};