您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

recharge-two.vue 21KB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. <template>
  2. <view class="wrapper">
  3. <view class="balance">ETC卡内余额:{{card.money/100}}</view>
  4. <view class="balance">修复金额:¥{{state.fee/100}}</view>
  5. <view class="balance">ETC卡号:{{card.cardId}}</view>
  6. <view class="balance">车牌号:{{card.vehiclePlate}}</view>
  7. <button type="default" class="button" @click="aa">确认修复</button>
  8. </view>
  9. </template>
  10. <script setup lang="ts">
  11. import {
  12. HexToStrig
  13. } from "@/utils/util/fileData.js";
  14. import {
  15. stringToJson
  16. } from "@/utils/network/encryption";
  17. import {
  18. onLoad,
  19. onShow
  20. } from "@dcloudio/uni-app";
  21. import {
  22. quanCheck,
  23. quanApply,
  24. quanXf,
  25. cardCzPayResultCheck,
  26. cardCzApply,
  27. cardCzPay,
  28. cardCzPayResult,
  29. cardCzXFCheck,
  30. quanConfirm,
  31. wechatAppID,
  32. wechatPayConfigId,
  33. wechatSecret,
  34. aliPayConfigId,
  35. obtainUserId,
  36. getOpenidApi
  37. } from "@/utils/network/api.js";
  38. import {
  39. request
  40. } from "@/utils/network/request.js";
  41. import {
  42. reactive
  43. } from "vue";
  44. import {
  45. navTo
  46. } from "@/utils/utils"
  47. import {
  48. msg
  49. } from "@/utils/utils";
  50. import {
  51. getItem,
  52. StorageKeys,
  53. setItem
  54. } from "@/utils/storage";
  55. const datas = require("../../../static/etcUtil/datas.js");
  56. const bluetoothUtil = require("../../../static/etcUtil/index.js");
  57. const cmd = require("../../../static/etcUtil/cmdConfig.js");
  58. const tools = require("../../../static/etcUtil/tools.js");
  59. const NFCAPI = require('../../../static/nfc/NFCAPI.js');
  60. const state = reactive({
  61. isShowBlue: false,
  62. openid: "",
  63. connectSuccess: undefined,
  64. fee: 5000,
  65. money: 50,
  66. orderNum: "",
  67. transWayName: "蓝牙",
  68. transWay: "blu", //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  69. cardId: "", //卡号 需要传参
  70. show: false,
  71. current: 0,
  72. tradeType: 12,
  73. payMoney: 0, //0 1直接走支付 0就是修复
  74. accountId: "",
  75. consumeId: "",//消费订单编号
  76. });
  77. //读卡信息
  78. const card : any = reactive({
  79. cardId: "",
  80. netId: "",
  81. cardType: "",
  82. startTime: "",
  83. endTime: "",
  84. userName: "",
  85. idNum: "",
  86. vehiclePlate: "",
  87. vehiclePlateColor: "",
  88. color: "",
  89. version: "",
  90. type: "",
  91. favourable: "",
  92. money: undefined,
  93. v_userType: "",
  94. });
  95. onLoad((option) => {
  96. console.log("来了=====")
  97. /*获取openId 用途:(用户支付)*/
  98. // #ifdef MP-WEIXIN
  99. getOpenID();/*传参*/
  100. // #endif
  101. console.log("开始option", option)
  102. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  103. state.connectSuccess = option.connectSuccess;
  104. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  105. if (option.rechargeMoney) { //圈存金额
  106. state.fee = option.rechargeMoney
  107. state.money = option.rechargeMoney / 100
  108. }
  109. if (option.orderNum) { //圈存金额
  110. state.orderNum = option.orderNum
  111. state.payMoney = Number(option.payMoney)
  112. }
  113. state.accountId = option.accountId
  114. console.log("option.orderNum", option, option.orderNum)
  115. //跳转过来走圈存流程
  116. // connectSuccess 2 从选择方式进来去圈存检测 1 只读卡
  117. // #ifdef MP-ALIPAY
  118. /*读卡*/
  119. // #endif
  120. getCardId();
  121. });
  122. const aa = () => {
  123. quanCheckActionTrue().then((val) => {
  124. console.log("圈存检测val", val)
  125. checkQuanCengEvent(val);
  126. });
  127. }
  128. function go(money) {
  129. let content = ""
  130. state.fee = money * 100
  131. //走蓝牙进行修复
  132. quanCheckActionTrue().then((val : any) => {
  133. console.log("圈存检测val", val)
  134. //如果 圈存检测正常
  135. if (val.chargeStatus === 1) {
  136. console.log(`进行充值检测`);
  137. czCheckAction().then((checkResult : any) => {
  138. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  139. if (checkResult.orders && checkResult.orders.length > 0) {
  140. //拿到订单,存起来
  141. state.orderNum = checkResult.orders[0].orderNum;
  142. // 检测用户是否存在有半条流水
  143. getCardId()
  144. } else {
  145. console.log('没有可修复的流水')
  146. }
  147. });
  148. } else {
  149. // 检测用户是否存在有半条流水
  150. getCardId()
  151. }
  152. });
  153. }
  154. /*点击充值按钮*/
  155. const rechargeAction = () => {
  156. state.fee = state.money * 100; //元换成分
  157. /*进行圈存检测,此处检测仅为校验圈存状态来决定去哪里*/
  158. console.log("进行圈存检测");
  159. quanCheckActionTrue().then((val : any) => {
  160. console.log("圈存检测接口返回", val)
  161. //如果 圈存检测正常
  162. if (val.chargeStatus === 1) {
  163. console.log(`进行充值检测`);
  164. czCheckAction().then((checkResult : any) => {
  165. console.log("进行充值检测", checkResult)
  166. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  167. if (checkResult.orders && checkResult.orders.length > 0) {
  168. state.fee = checkResult.orders[0]['rechargeMoney']
  169. state.money = checkResult.orders[0]['rechargeMoney'] / 100
  170. //拿到订单,存起来
  171. state.orderNum = checkResult.orders[0].orderNum;
  172. //链接蓝牙
  173. go(state.money)
  174. } else {
  175. cardCzApplyAction().then((applyResult : any) => {
  176. //拿到订单 存起来
  177. state.orderNum = applyResult.orderNum;
  178. //如果订单没有支付 走支付
  179. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  180. //走支付
  181. console.log("走支付");
  182. // #ifdef MP-WEIXIN
  183. wxPayment();
  184. // #endif
  185. // #ifdef MP-ALIPAY
  186. aliPayment()
  187. // #endif
  188. }
  189. });
  190. }
  191. });
  192. } else {
  193. //走蓝牙进行修复
  194. // 圈存检测异常,继续上次圈存 chargeStatus==2
  195. let fixFee = val.fixFee / 100
  196. console.log("fixFee", fixFee)
  197. go(fixFee)
  198. }
  199. });
  200. };
  201. /*读卡*/
  202. const getCardId = (readCard) => {
  203. console.log("======获取卡信息======");
  204. let cmdArr = [
  205. cmd.HOME_DIRECTORY,
  206. //选择主目
  207. cmd.APPLICATION_DIRECTORY,
  208. //选择文件1001--DF01联网收费应用目录
  209. cmd.CMD_READBINARY,
  210. //15文件--卡片发行基本数据文件
  211. cmd.CMD_GETBALANCE,
  212. //钱包
  213. ];
  214. tools.showLoadingAlert("正在执行指令");
  215. transCmd(cmdArr, function (res : any) {
  216. getCardIdReturn(res);
  217. })
  218. };
  219. function getCardIdReturn(res : any) {
  220. tools.hideLoadingAlert();
  221. //10:写卡 20:写OBU
  222. let str = res[2].substring(res[2].length - 4, res[2].length);
  223. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  224. if (str == "9000" || str3 == "9000") {
  225. if (res[2].length > 86 || res[3] >= 12) {
  226. state.cardId = res[2].substring(20, 40); //卡号
  227. card.cardId = res[2].substring(20, 40); //卡号
  228. card.startTime = res[2].substring(40, 48);
  229. card.endTime = res[2].substring(48, 56);
  230. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  231. card.netId = res[2].substring(20, 24);
  232. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  233. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  234. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  235. console.log("======卡信息======", card, card.money);
  236. card.vehiclePlate = HexToStrig(res[2].substring(56, 80));
  237. } else {
  238. console.error("CMD_READBINARY指令长度不符" + res[2]);
  239. tools.hideLoadingAlert();
  240. }
  241. }
  242. console.error("CMD_READBINARY指令长度不符" + res[2]);
  243. tools.hideLoadingAlert();
  244. }
  245. const checkQuanCengEvent = (val : any) => {
  246. // 圈存检测正常(无半条流水)
  247. if (val.chargeStatus === 1) {
  248. let cmdArr = val.command.split(",");
  249. uni.showLoading({
  250. title: "写入中",
  251. });
  252. transCmd(cmdArr, function (res : any) {
  253. let response = res.toString();
  254. var dic = {
  255. command: val.command,
  256. cosResponse: response,
  257. };
  258. uni.hideLoading();
  259. quanApplyAction(dic).then((value : any) => {
  260. console.log("圈存申请完后的结果");
  261. console.log(value.commandType, value);
  262. state.consumeId = value.consumeId
  263. //圈存初始化验证通过 , 进行圈存
  264. if (value.commandType === 2) {
  265. uanConfirmAction(value);
  266. } else {
  267. console.log("第二次70", value)
  268. let cmdArr = value.command.split(",");
  269. uni.showLoading({
  270. title: "写入中",
  271. });
  272. transCmd(cmdArr, function (res : any) {
  273. let response = res.toString();
  274. var dic = {
  275. command: val.command,
  276. cosResponse: response,
  277. };
  278. uni.hideLoading();
  279. quanApplyAction(dic).then((values) => {
  280. state.consumeId = values.consumeId
  281. console.log("圈存申请完后的结果");
  282. uanConfirmAction(values);
  283. });
  284. })
  285. }
  286. });
  287. });
  288. } else {
  289. // 圈存检测异常(有半条流水)
  290. let cmdArr = val.command.split(",");
  291. uni.showLoading({
  292. title: "写入中",
  293. });
  294. transCmd(cmdArr, function (res : any) {
  295. var status = res[1].substring(res[1].length - 4, res[1].length);
  296. console.log("打印状态");
  297. console.log(status);
  298. if (status === "9000") {
  299. console.log("修复指令入参");
  300. let response = res.toString();
  301. var dic = {
  302. command: val.command,
  303. cosResponse: response,
  304. rechargeId: val.rechargeId,
  305. };
  306. quanFixAction(dic).then((value : any) => {
  307. state.orderNum = value.orderId
  308. state.tradeType = value.tradeType
  309. console.log(value);
  310. console.log("修复结果返回");
  311. var fixStatus = value.fixStatus;
  312. //圈存修复COS指令Response信息不足,重新进行修复初始化
  313. if (fixStatus === 3) {
  314. let xfcmdArr = value.command.split(",");
  315. transCmd(xfcmdArr, function (resValueData) {
  316. var status = resValueData[1].substring(
  317. resValueData[1].length - 4,
  318. resValueData[1].length
  319. );
  320. console.log("打印状态");
  321. console.log(status);
  322. if (status === "9000") {
  323. console.log(resValueData);
  324. var valueResponse = resValueData.toString();
  325. console.log(response);
  326. var applyDic = {
  327. command: value.command,
  328. cosResponse: valueResponse,
  329. rechargeId: value.rechargeId,
  330. };
  331. console.log("消费成功");
  332. quanApplyAction(applyDic).then((applyValue) => {
  333. state.consumeId = applyValue.consumeId
  334. uanConfirmAction(applyValue);
  335. });
  336. }
  337. });
  338. } else if (fixStatus === 2) {
  339. uanConfirmSucessAction(value).then((confirmResult) => {
  340. console.log("充值成功2222222")
  341. // readCard();
  342. setTimeout(() => {
  343. msg("修复成功");
  344. navTo(`./result?cardId=${card.cardId}`)
  345. }, 2000)
  346. });
  347. } else if (fixStatus === 1) {
  348. quanCheckActionTrue().then((val) => {
  349. checkQuanCengEvent(val);
  350. });
  351. }
  352. });
  353. uni.hideLoading();
  354. }
  355. });
  356. }
  357. };
  358. /*透传*/
  359. const transCmd = (cmd : any, click : any) => {
  360. if (state.transWay == 'blu') {
  361. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  362. click(res);
  363. });
  364. } else {
  365. //nfc透传
  366. NFCAPI.transCmd(cmd, function (res : any) {
  367. tools.hideLoadingAlert();
  368. if (res.code == 0) {
  369. click(res.data);
  370. } else {
  371. //透传失败返回
  372. tools.alertF(res.msg);
  373. }
  374. });
  375. }
  376. };
  377. const quanCheckActionTrue = () => {
  378. console.log("进行真实圈存检测");
  379. var data = {
  380. cardId: card.cardId,
  381. fee: state.fee,
  382. preBalance: card.money,
  383. tradeType: 12,
  384. };
  385. const options = {
  386. type: 2,
  387. data: data,
  388. method: "POST",
  389. showLoading: true,
  390. };
  391. return new Promise(async (resolve, reject) => {
  392. const res = await request(quanCheck, options);
  393. const data = stringToJson(res.bizContent);
  394. resolve(data);
  395. }).catch((error) => {
  396. reject(error);
  397. });
  398. };
  399. /*充值消费*/
  400. const cardCzXFCheckAction = () => {
  401. var data = {
  402. cardId: card.cardId, //修复初始化的指令
  403. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  404. orderNum: state.orderNum, //充值流水号
  405. };
  406. const options = {
  407. type: 2,
  408. data: data,
  409. method: "POST",
  410. showLoading: true,
  411. };
  412. return new Promise(async (resolve, reject) => {
  413. const res = await request(cardCzXFCheck, options);
  414. const data = stringToJson(res.bizContent);
  415. resolve(data);
  416. }).catch((error) => {
  417. reject(error);
  418. });
  419. };
  420. /*圈存修复*/
  421. const quanFixAction = (val) => {
  422. var data = {
  423. command: val.command, //修复初始化的指令
  424. cosResponse: val.cosResponse, //修复初始化结果
  425. rechargeId: val.rechargeId, //充值流水号
  426. };
  427. const options = {
  428. type: 2,
  429. data: data,
  430. method: "POST",
  431. showLoading: true,
  432. };
  433. return new Promise(async (resolve, reject) => {
  434. const res = await request(quanXf, options);
  435. const data = stringToJson(res.bizContent);
  436. resolve(data);
  437. }).catch((error) => {
  438. reject(error);
  439. });
  440. };
  441. /*圈存申请*/
  442. const quanApplyAction = (data) => {
  443. console.log("圈存申请data====", data, data.rechargeId)
  444. var form = {
  445. cardId: card.cardId,
  446. fee: state.fee,
  447. preBalance: card.money,
  448. tradeType: state.tradeType,
  449. command: data.command,
  450. cosResponse: data.cosResponse,
  451. orderId: state.orderNum,
  452. rechargeId: data.rechargeId,
  453. openId: getItem(StorageKeys.OpenId),
  454. accountId: state.accountId
  455. };
  456. const options = {
  457. type: 2,
  458. data: form,
  459. method: "POST",
  460. showLoading: true,
  461. };
  462. return new Promise(async (resolve, reject) => {
  463. const res = await request(quanApply, options);
  464. const data = stringToJson(res.bizContent);
  465. resolve(data);
  466. }).catch((error) => {
  467. reject(error);
  468. });
  469. };
  470. /*圈存确认*/
  471. const uanConfirmAction = (data : any) => {
  472. console.log("圈存确认进入");
  473. let cmdArr = data.command.split(",");
  474. console.log(cmdArr);
  475. transCmd(cmdArr, function (res : any) {
  476. console.log("圈存透传");
  477. console.log(res);
  478. var arraylenth = res.length;
  479. var status = res[arraylenth - 1].substring(
  480. res[arraylenth - 1].length - 4,
  481. res[arraylenth - 1].length
  482. );
  483. console.log("打印圈存确认指令状态");
  484. if (status === "9000") {
  485. var form = {
  486. command: data.command,
  487. cosResponse: res.toString(),
  488. rechargeId: data.rechargeId,
  489. paidAmount: state.fee,
  490. giftAmount: 0,
  491. tradeType: 12,
  492. consumeId: state.consumeId,
  493. accountId: state.accountId
  494. };
  495. const options = {
  496. type: 2,
  497. data: form,
  498. method: "POST",
  499. showLoading: true,
  500. };
  501. return new Promise(async () => {
  502. const res = await request(quanConfirm, options);
  503. const data = stringToJson(res.bizContent);
  504. console.log("data充值成功", data);
  505. // readCard()
  506. console.log("充值成功2222222")
  507. setTimeout(() => {
  508. msg("修复成功");
  509. navTo(`./result?cardId=${card.cardId}`)
  510. }, 2000)
  511. }).catch((error) => {
  512. console.log('输出内容', error)
  513. });
  514. }
  515. });
  516. };
  517. const uanConfirmSucessAction = (data) => {
  518. var form = {
  519. command: data.command,
  520. cosResponse: "9000",
  521. rechargeId: data.rechargeId,
  522. paidAmount: state.fee,
  523. giftAmount: 0,
  524. tradeType: 12,
  525. accountId: state.accountId
  526. };
  527. const options = {
  528. type: 2,
  529. data: form,
  530. method: "POST",
  531. showLoading: true,
  532. };
  533. return new Promise(async (resolve, reject) => {
  534. const res = await request(quanConfirm, options);
  535. const data = stringToJson(res.bizContent);
  536. resolve(data);
  537. console.log("uanConfirmSucessAction", data)
  538. }).catch((error) => {
  539. reject(error);
  540. });
  541. };
  542. /*充值检测*/
  543. const czCheckAction = () => {
  544. var form = {
  545. cardId: state.cardId,
  546. openId: getItem(StorageKeys.OpenId),
  547. };
  548. const options = {
  549. type: 2,
  550. data: form,
  551. method: "POST",
  552. showLoading: true,
  553. };
  554. return new Promise(async (resolve, reject) => {
  555. const res = await request(cardCzPayResultCheck, options);
  556. const data = stringToJson(res.bizContent);
  557. console.log("充值检测", data)
  558. resolve(data);
  559. }).catch((error) => {
  560. reject(error);
  561. });
  562. };
  563. /*充值申请*/
  564. const cardCzApplyAction = () => {
  565. var data = {
  566. cardId: state.cardId,
  567. openId: getItem(StorageKeys.OpenId),
  568. rechargeMoney: state.fee,
  569. };
  570. const options = {
  571. type: 2,
  572. data: data,
  573. method: "POST",
  574. showLoading: true,
  575. };
  576. return new Promise(async (resolve, reject) => {
  577. const res = await request(cardCzApply, options);
  578. const data = stringToJson(res.bizContent);
  579. resolve(data);
  580. }).catch((error) => {
  581. reject(error);
  582. });
  583. };
  584. //获取微信小程序openid
  585. const getOpenID = () => {
  586. uni.login({
  587. provider: "weixin",
  588. success: function (e) {
  589. getOpenid(e.code);
  590. },
  591. fail: function () {
  592. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  593. },
  594. });
  595. };
  596. const getOpenid = (code) => {
  597. const options = {
  598. type: 2,
  599. data: {
  600. "jsCode": code
  601. },
  602. method: "POST",
  603. showLoading: true,
  604. };
  605. // #ifdef MP-WEIXIN
  606. request(getOpenidApi, options).then((res) => {
  607. const result = stringToJson(res.bizContent);
  608. console.log("获取微信小程序openid", result);
  609. const openidData = stringToJson(result.data);
  610. state.openid = openidData.openid
  611. /*读卡*/
  612. getCardId(1);
  613. });
  614. // #endif
  615. }
  616. //掉起微信支付
  617. const wxPayment = () => {
  618. // #ifdef MP-WEIXIN
  619. const options = {
  620. type: 2,
  621. data: {
  622. openId: getItem(StorageKeys.OpenId),
  623. wxOpenId: state.openid,
  624. cardId: state.cardId,
  625. orderNum: state.orderNum,
  626. payConfigId: wechatPayConfigId,
  627. body: "储值卡充值",
  628. },
  629. method: "POST",
  630. showLoading: true,
  631. };
  632. request(cardCzPay, options).then((res) => {
  633. const data = stringToJson(res.bizContent);
  634. uni.requestPayment({
  635. provider: "wxpay",
  636. orderInfo: "",
  637. timeStamp: data.timestamp,
  638. nonceStr: data.noncestr,
  639. package: data.wxPackage ? data.wxPackage : "",
  640. signType: data.signType,
  641. paySign: data.sign,
  642. success: function () {
  643. //回调订单状态
  644. console.log("回调订单状态");
  645. checkOrder();
  646. },
  647. fail: function (err) {
  648. confirm(err, () => { }, "支付失败", false);
  649. },
  650. });
  651. });
  652. // #endif
  653. };
  654. //掉起支付宝支付
  655. const aliPayment = () => {
  656. // #ifdef MP-ALIPAY
  657. my.getAuthCode({
  658. scopes: 'auth_base',
  659. success: res => {
  660. const optionsUser = {
  661. type: 2,
  662. data: {
  663. payConfigId: aliPayConfigId,
  664. code: res.authCode
  665. },
  666. method: "POST",
  667. showLoading: true,
  668. };
  669. request(obtainUserId, optionsUser).then((res) => {
  670. const data = stringToJson(res.bizContent);
  671. const optionsali = {
  672. type: 2,
  673. data: {
  674. openId: getItem(StorageKeys.OpenId),
  675. wxOpenId: data.openId,
  676. cardId: state.cardId,
  677. orderNum: state.orderNum,
  678. payConfigId: "6a9a54123456578934edfre132b1234",
  679. body: "储值卡充值",
  680. },
  681. method: "POST",
  682. showLoading: true,
  683. };
  684. request(cardCzPay, optionsali).then((res) => {
  685. const data = stringToJson(res.bizContent);
  686. my.tradePay({
  687. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  688. tradeNO: data.tranPackage,
  689. success: res => {
  690. console.log("支付成功", res);
  691. checkOrder();
  692. },
  693. fail: res => {
  694. confirm(res, () => { }, "支付失败", false);
  695. },
  696. });
  697. });
  698. });
  699. },
  700. fail: err => {
  701. console.log('my.getAuthCode 调用失败', err)
  702. }
  703. });
  704. // #endif
  705. };
  706. //支付成功改变订单状态
  707. const checkOrder = () => {
  708. const options = {
  709. type: 2,
  710. data: {
  711. cardId: state.cardId,
  712. openId: getItem(StorageKeys.OpenId),
  713. orderNum: state.orderNum,
  714. },
  715. method: "POST",
  716. showLoading: true,
  717. };
  718. request(cardCzPayResult, options).then((res) => {
  719. const data = stringToJson(res.bizContent);
  720. if (data.tradeState === "SUCCESS") {
  721. getCardId();
  722. }
  723. console.log(data);
  724. });
  725. };
  726. const readCard = () => {
  727. let cmdArr = [
  728. cmd.HOME_DIRECTORY,
  729. //选择主目
  730. cmd.APPLICATION_DIRECTORY,
  731. //选择文件1001--DF01联网收费应用目录
  732. cmd.CMD_READBINARY,
  733. //15文件--卡片发行基本数据文件
  734. cmd.CMD_GETBALANCE,
  735. //钱包
  736. ];
  737. tools.showLoadingAlert("正在执行指令");
  738. transCmd(cmdArr, function (res : any) {
  739. tools.hideLoadingAlert();
  740. //10:写卡 20:写OBU
  741. let str = res[2].substring(res[2].length - 4, res[2].length);
  742. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  743. if (str == "9000" || str3 == "9000") {
  744. if (res[2].length > 86 || res[3] >= 12) {
  745. state.cardId = res[2].substring(20, 40); //卡号
  746. card.cardId = res[2].substring(20, 40); //卡号
  747. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  748. }
  749. }
  750. })
  751. }
  752. </script>
  753. <style>
  754. .balance {
  755. margin-left: 30rpx;
  756. font-size: 32rpx;
  757. color: #000;
  758. margin-bottom: 10rpx;
  759. }
  760. label {
  761. display: flex;
  762. justify-content: space-between;
  763. margin-top: 30rpx;
  764. }
  765. .button {
  766. height: 80rpx;
  767. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  768. border-radius: 40rpx;
  769. font-size: 32rpx;
  770. font-weight: 400;
  771. color: #ffffff !important;
  772. line-height: 80rpx;
  773. margin-top: 100rpx;
  774. width: 80%;
  775. }
  776. </style>