123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // plugin/etc/pages/exbSignGetAuth/exbSignGetAuth.js
-
-
- import {
- configObj,
- updateSignCarSeriveState
- } from "../../../config.js"
- import {
- sm3
- } from "../../../new-utils/SM3.js";
- const network = require('../../../network/index');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- isNeedLogin: false,
- openId: "",
- orderNo: "",
- subOpenId: "",
- accessToken: "",
- loadMsg: "请稍后...",
- isJumpSign: false,
- signType: 0, // 0 协议初始界面 1 查询协议状态界面 2 验证成功 3 签约失败,
- failMsg: "车主服务签约失败,请稍后重试",
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- updateSignCarSeriveState();
- this.configData(options)
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.configIsNeedLogin()
- },
- /// -------------- 工具类型 ---------------- ///
- configData(options) {
- const orderNo = options?.orderNo
- if (orderNo) {
- this.setData({
- orderNo
- })
- }
- },
-
- configIsNeedLogin() {
- this.setData({
- isNeedLogin: this.data.subOpenId == ""
- })
- if (this.data.isJumpSign) {
- this.data.isJumpSign = false
- this.setData({
- signType: 1,
- })
- this.configSignParams(1)
- }
- },
-
-
- configSignStatus(state = 0) {
- console.log(state);
- updateSignCarSeriveState(state)
- wx.navigateBack();
- },
-
- /// -------------- 网络请求 ---------------- ///
-
- async configSignParams(type = 0) {
- const {
- orderNo,
- subOpenId,
- } = this.data
- if (orderNo == "" || subOpenId == '') {
- wx.hideLoading()
- if (type == 0) {
- wx.showModal({
- content: '缺少必要参数,请退出重新进入',
- showCancel: false,
- complete: () => {
- wx.navigateBack();
- }
- })
- } else {
- wx.navigateBack();
- }
- return
- }
-
- wx.showLoading({
- title: type == 0 ? '签约中...' : '查询中...',
- })
- const res = await (type == 0 ? network.etc.getCarSign({
- orderNo,
- subOpenId,
- signChannelType: 1,
- }) : network.etc.getSignStatus({
- orderNo,
- subOpenId,
- signChannelType: 1,
- }))
- wx.hideLoading()
- this.configSignToJump(res, type)
- },
-
-
- configSignToJump(res, type = 0) {
- const {
- data,
- code,
- message,
- } = res;
- console.log(res)
- const that = this;
- if (code == 0) {
- const {
- appId,
- channelType,
- mchId,
- nonceStr,
- path,
- plateNumber,
- sign,
- signType,
- subAppId,
- subMchId,
- subOpenId,
- tradeScene,
- userState,
- } = data;
- if (type == 0) {
- const extraData = {
- "appid": appId,
- "sub_appid": subAppId,
- "mch_id": mchId,
- "sub_mch_id": subMchId,
- "nonce_str": nonceStr,
- "sign_type": signType,
- "trade_scene": tradeScene,
- "plate_number": plateNumber,
- "sub_openid": subOpenId,
- "sign": sign,
- "channel_type": channelType,
- }
- // 未签约
- wx.navigateToMiniProgram({
- appId: 'wxbcad394b3d99dac9',
- extraData,
- path: 'pages/route/index',
- success(res) {
- that.setData({
- isJumpSign: true,
- })
- console.log("跳转车主小程序")
- },
- fail(res) {
- console.log("未跳转小程序", res)
- },
- })
- } else {
- if (userState == "UNAUTHORIZED") {
- that.setData({
- signType: 0,
- })
- wx.showToast({
- title: "车主服务暂未签约",
- icon: 'none'
- })
- } else if (userState == "NORMAL") {
- that.setData({
- signType: 2,
- })
- setTimeout(function () {
- that.configSignStatus()
- }, 500);
-
- } else if (userState == "PAUSED") {
- this.setData({
- signType: 3,
- failMsg: '已暂停车主服务',
- })
- } else if (userState == "OVERDUE") {
- this.setData({
- signType: 3,
- failMsg: "用户已开通车主服务,但欠费状态。提示用户还款,请跳转到车主服务",
- })
- } else {
- wx.showToast({
- title: message,
- icon: 'none'
- })
- }
- }
- } else {
- console.log(res)
- if (type == 1) {
- this.setData({
- signType: 3,
- failMsg: message || "签约状态查询失败,请稍后重试",
- })
- } else {
- wx.showModal({
- content: message || "业务校验失败",
- showCancel: false,
- })
- }
- }
- },
- async getOpenId(jsCode) {
- const res = await network.common.getOpenId(jsCode);
- console.log(res)
- if (res.code == 0 && res.data && res.data.openid) {
- this.setData({
- isNeedLogin: false,
- subOpenId: res.data.openid,
- })
- this.configSignParams()
- } else {
- wx.hideLoading()
- wx.showToast({
- title: res.message,
- icon: "none"
- })
- }
- },
-
- /// -------------- 触发事件 ---------------- ///
- configReloadLogin(e) {
- wx.showLoading({
- title: '登录中...',
- })
- const code = e.detail.value;
- this.getOpenId(code)
- },
-
- onTapSign() {
- // const sm3Data = "appId=52188934&bizContent=FwMunxmi0MQs5+Pe+p7xtY+lQvMH4TvBV1L0KeGcc48U4AGHhgUoKSEcnLGLHGvZ&signType=SM3&encryptType=SM4×tamp=2025-09-02T18:35:29&ifCode=ATS_WEIXIN_GETWECHATOPENID&reqId=52188934_20250902183529146_53511"
- // let sign = sm3(sm3Data, configObj.sm3Key);
- // console.log(sign)
-
- this.configSignParams()
- },
- tapReload() {
- this.configSignStatus(1);
- }
-
- })
|