You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exbSignGetAuth.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // plugin/etc/pages/exbSignGetAuth/exbSignGetAuth.js
  2. import {
  3. configObj,
  4. updateSignCarSeriveState
  5. } from "../../../config.js"
  6. import {
  7. sm3
  8. } from "../../../new-utils/SM3.js";
  9. const network = require('../../../network/index');
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. isNeedLogin: false,
  16. openId: "",
  17. orderNo: "",
  18. subOpenId: "",
  19. accessToken: "",
  20. loadMsg: "请稍后...",
  21. isJumpSign: false,
  22. signType: 0, // 0 协议初始界面 1 查询协议状态界面 2 验证成功 3 签约失败,
  23. failMsg: "车主服务签约失败,请稍后重试",
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad(options) {
  29. updateSignCarSeriveState();
  30. this.configData(options)
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow() {
  36. this.configIsNeedLogin()
  37. },
  38. /// -------------- 工具类型 ---------------- ///
  39. configData(options) {
  40. const orderNo = options?.orderNo
  41. if (orderNo) {
  42. this.setData({
  43. orderNo
  44. })
  45. }
  46. },
  47. configIsNeedLogin() {
  48. this.setData({
  49. isNeedLogin: this.data.subOpenId == ""
  50. })
  51. if (this.data.isJumpSign) {
  52. this.data.isJumpSign = false
  53. this.setData({
  54. signType: 1,
  55. })
  56. this.configSignParams(1)
  57. }
  58. },
  59. configSignStatus(state = 0) {
  60. console.log(state);
  61. updateSignCarSeriveState(state)
  62. wx.navigateBack();
  63. },
  64. /// -------------- 网络请求 ---------------- ///
  65. async configSignParams(type = 0) {
  66. const {
  67. orderNo,
  68. subOpenId,
  69. } = this.data
  70. if (orderNo == "" || subOpenId == '') {
  71. wx.hideLoading()
  72. if (type == 0) {
  73. wx.showModal({
  74. content: '缺少必要参数,请退出重新进入',
  75. showCancel: false,
  76. complete: () => {
  77. wx.navigateBack();
  78. }
  79. })
  80. } else {
  81. wx.navigateBack();
  82. }
  83. return
  84. }
  85. wx.showLoading({
  86. title: type == 0 ? '签约中...' : '查询中...',
  87. })
  88. const res = await (type == 0 ? network.etc.getCarSign({
  89. orderNo,
  90. subOpenId,
  91. signChannelType: 1,
  92. }) : network.etc.getSignStatus({
  93. orderNo,
  94. subOpenId,
  95. signChannelType: 1,
  96. }))
  97. wx.hideLoading()
  98. this.configSignToJump(res, type)
  99. },
  100. configSignToJump(res, type = 0) {
  101. const {
  102. data,
  103. code,
  104. message,
  105. } = res;
  106. console.log(res)
  107. const that = this;
  108. if (code == 0) {
  109. const {
  110. appId,
  111. channelType,
  112. mchId,
  113. nonceStr,
  114. path,
  115. plateNumber,
  116. sign,
  117. signType,
  118. subAppId,
  119. subMchId,
  120. subOpenId,
  121. tradeScene,
  122. userState,
  123. } = data;
  124. if (type == 0) {
  125. const extraData = {
  126. "appid": appId,
  127. "sub_appid": subAppId,
  128. "mch_id": mchId,
  129. "sub_mch_id": subMchId,
  130. "nonce_str": nonceStr,
  131. "sign_type": signType,
  132. "trade_scene": tradeScene,
  133. "plate_number": plateNumber,
  134. "sub_openid": subOpenId,
  135. "sign": sign,
  136. "channel_type": channelType,
  137. }
  138. // 未签约
  139. wx.navigateToMiniProgram({
  140. appId: 'wxbcad394b3d99dac9',
  141. extraData,
  142. path: 'pages/route/index',
  143. success(res) {
  144. that.setData({
  145. isJumpSign: true,
  146. })
  147. console.log("跳转车主小程序")
  148. },
  149. fail(res) {
  150. console.log("未跳转小程序", res)
  151. },
  152. })
  153. } else {
  154. if (userState == "UNAUTHORIZED") {
  155. that.setData({
  156. signType: 0,
  157. })
  158. wx.showToast({
  159. title: "车主服务暂未签约",
  160. icon: 'none'
  161. })
  162. } else if (userState == "NORMAL") {
  163. that.setData({
  164. signType: 2,
  165. })
  166. setTimeout(function () {
  167. that.configSignStatus()
  168. }, 500);
  169. } else if (userState == "PAUSED") {
  170. this.setData({
  171. signType: 3,
  172. failMsg: '已暂停车主服务',
  173. })
  174. } else if (userState == "OVERDUE") {
  175. this.setData({
  176. signType: 3,
  177. failMsg: "用户已开通车主服务,但欠费状态。提示用户还款,请跳转到车主服务",
  178. })
  179. } else {
  180. wx.showToast({
  181. title: message,
  182. icon: 'none'
  183. })
  184. }
  185. }
  186. } else {
  187. console.log(res)
  188. if (type == 1) {
  189. this.setData({
  190. signType: 3,
  191. failMsg: message || "签约状态查询失败,请稍后重试",
  192. })
  193. } else {
  194. wx.showModal({
  195. content: message || "业务校验失败",
  196. showCancel: false,
  197. })
  198. }
  199. }
  200. },
  201. async getOpenId(jsCode) {
  202. const res = await network.common.getOpenId(jsCode);
  203. console.log(res)
  204. if (res.code == 0 && res.data && res.data.openid) {
  205. this.setData({
  206. isNeedLogin: false,
  207. subOpenId: res.data.openid,
  208. })
  209. this.configSignParams()
  210. } else {
  211. wx.hideLoading()
  212. wx.showToast({
  213. title: res.message,
  214. icon: "none"
  215. })
  216. }
  217. },
  218. /// -------------- 触发事件 ---------------- ///
  219. configReloadLogin(e) {
  220. wx.showLoading({
  221. title: '登录中...',
  222. })
  223. const code = e.detail.value;
  224. this.getOpenId(code)
  225. },
  226. onTapSign() {
  227. // const sm3Data = "appId=52188934&bizContent=FwMunxmi0MQs5+Pe+p7xtY+lQvMH4TvBV1L0KeGcc48U4AGHhgUoKSEcnLGLHGvZ&signType=SM3&encryptType=SM4&timestamp=2025-09-02T18:35:29&ifCode=ATS_WEIXIN_GETWECHATOPENID&reqId=52188934_20250902183529146_53511"
  228. // let sign = sm3(sm3Data, configObj.sm3Key);
  229. // console.log(sign)
  230. this.configSignParams()
  231. },
  232. tapReload() {
  233. this.configSignStatus(1);
  234. }
  235. })