選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

recharge-two.vue 21KB

1年前
1年前
1年前
10ヶ月前
1年前
10ヶ月前
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年前
10ヶ月前
1年前
9ヶ月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. stringToJson
  13. } from "@/utils/network/encryption";
  14. import {
  15. onLoad,
  16. onShow
  17. } from "@dcloudio/uni-app";
  18. import {
  19. quanCheck,
  20. quanApply,
  21. quanXf,
  22. cardCzPayResultCheck,
  23. cardCzApply,
  24. cardCzPay,
  25. cardCzPayResult,
  26. cardCzXFCheck,
  27. quanConfirm,
  28. wechatAppID,
  29. wechatPayConfigId,
  30. wechatSecret,
  31. aliPayConfigId,
  32. obtainUserId,
  33. getOpenId
  34. } from "@/utils/network/api.js";
  35. import {
  36. request,requestNew
  37. } from "@/utils/network/request.js";
  38. import {
  39. reactive
  40. } from "vue";
  41. import {
  42. navTo
  43. } from "@/utils/utils"
  44. import {
  45. msg
  46. } from "@/utils/utils";
  47. import {
  48. getItem,
  49. StorageKeys,
  50. setItem
  51. } from "@/utils/storage";
  52. import {
  53. decryptCardVehicleInformation
  54. } from "@/datas/publicRequest";
  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. decryptCardVehicleInformation(res[2].substring(56, 80), function (res) {
  237. card.vehiclePlate =res;
  238. });
  239. } else {
  240. console.error("CMD_READBINARY指令长度不符" + res[2]);
  241. tools.hideLoadingAlert();
  242. }
  243. }
  244. console.error("CMD_READBINARY指令长度不符" + res[2]);
  245. tools.hideLoadingAlert();
  246. }
  247. const checkQuanCengEvent = (val : any) => {
  248. // 圈存检测正常(无半条流水)
  249. if (val.chargeStatus === 1) {
  250. let cmdArr = val.command.split(",");
  251. uni.showLoading({
  252. title: "写入中",
  253. });
  254. transCmd(cmdArr, function (res : any) {
  255. let response = res.toString();
  256. var dic = {
  257. command: val.command,
  258. cosResponse: response,
  259. };
  260. uni.hideLoading();
  261. quanApplyAction(dic).then((value : any) => {
  262. console.log("圈存申请完后的结果");
  263. console.log(value.commandType, value);
  264. state.consumeId = value.consumeId
  265. //圈存初始化验证通过 , 进行圈存
  266. if (value.commandType === 2) {
  267. uanConfirmAction(value);
  268. } else {
  269. console.log("第二次70", value)
  270. let cmdArr = value.command.split(",");
  271. uni.showLoading({
  272. title: "写入中",
  273. });
  274. transCmd(cmdArr, function (res : any) {
  275. let response = res.toString();
  276. var dic = {
  277. command: val.command,
  278. cosResponse: response,
  279. };
  280. uni.hideLoading();
  281. quanApplyAction(dic).then((values) => {
  282. state.consumeId = values.consumeId
  283. console.log("圈存申请完后的结果");
  284. uanConfirmAction(values);
  285. });
  286. })
  287. }
  288. });
  289. });
  290. } else {
  291. // 圈存检测异常(有半条流水)
  292. let cmdArr = val.command.split(",");
  293. uni.showLoading({
  294. title: "写入中",
  295. });
  296. transCmd(cmdArr, function (res : any) {
  297. var status = res[1].substring(res[1].length - 4, res[1].length);
  298. console.log("打印状态");
  299. console.log(status);
  300. if (status === "9000") {
  301. console.log("修复指令入参");
  302. let response = res.toString();
  303. var dic = {
  304. command: val.command,
  305. cosResponse: response,
  306. rechargeId: val.rechargeId,
  307. };
  308. quanFixAction(dic).then((value : any) => {
  309. state.orderNum = value.orderId
  310. state.tradeType = value.tradeType
  311. console.log(value);
  312. console.log("修复结果返回");
  313. var fixStatus = value.fixStatus;
  314. //圈存修复COS指令Response信息不足,重新进行修复初始化
  315. if (fixStatus === 3) {
  316. let xfcmdArr = value.command.split(",");
  317. transCmd(xfcmdArr, function (resValueData) {
  318. var status = resValueData[1].substring(
  319. resValueData[1].length - 4,
  320. resValueData[1].length
  321. );
  322. console.log("打印状态");
  323. console.log(status);
  324. if (status === "9000") {
  325. console.log(resValueData);
  326. var valueResponse = resValueData.toString();
  327. console.log(response);
  328. var applyDic = {
  329. command: value.command,
  330. cosResponse: valueResponse,
  331. rechargeId: value.rechargeId,
  332. };
  333. console.log("消费成功");
  334. quanApplyAction(applyDic).then((applyValue) => {
  335. state.consumeId = applyValue.consumeId
  336. uanConfirmAction(applyValue);
  337. });
  338. }
  339. });
  340. } else if (fixStatus === 2) {
  341. uanConfirmSucessAction(value).then((confirmResult) => {
  342. console.log("充值成功2222222")
  343. // readCard();
  344. setTimeout(() => {
  345. msg("修复成功");
  346. navTo(`./result?cardId=${card.cardId}`)
  347. }, 2000)
  348. });
  349. } else if (fixStatus === 1) {
  350. quanCheckActionTrue().then((val) => {
  351. checkQuanCengEvent(val);
  352. });
  353. }
  354. });
  355. uni.hideLoading();
  356. }
  357. });
  358. }
  359. };
  360. /*透传*/
  361. const transCmd = (cmd : any, click : any) => {
  362. if (state.transWay == 'blu') {
  363. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  364. click(res);
  365. });
  366. } else {
  367. //nfc透传
  368. NFCAPI.transCmd(cmd, function (res : any) {
  369. tools.hideLoadingAlert();
  370. if (res.code == 0) {
  371. click(res.data);
  372. } else {
  373. //透传失败返回
  374. tools.alertF(res.msg);
  375. }
  376. });
  377. }
  378. };
  379. const quanCheckActionTrue = () => {
  380. console.log("进行真实圈存检测");
  381. var data = {
  382. cardId: card.cardId,
  383. fee: state.fee,
  384. preBalance: card.money,
  385. tradeType: 12,
  386. };
  387. const options = {
  388. type: 2,
  389. data: data,
  390. method: "POST",
  391. showLoading: true,
  392. };
  393. return new Promise(async (resolve, reject) => {
  394. const res = await request(quanCheck, options);
  395. const data = stringToJson(res.bizContent);
  396. resolve(data);
  397. }).catch((error) => {
  398. reject(error);
  399. });
  400. };
  401. /*充值消费*/
  402. const cardCzXFCheckAction = () => {
  403. var data = {
  404. cardId: card.cardId, //修复初始化的指令
  405. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  406. orderNum: state.orderNum, //充值流水号
  407. };
  408. const options = {
  409. type: 2,
  410. data: data,
  411. method: "POST",
  412. showLoading: true,
  413. };
  414. return new Promise(async (resolve, reject) => {
  415. const res = await request(cardCzXFCheck, options);
  416. const data = stringToJson(res.bizContent);
  417. resolve(data);
  418. }).catch((error) => {
  419. reject(error);
  420. });
  421. };
  422. /*圈存修复*/
  423. const quanFixAction = (val) => {
  424. var data = {
  425. command: val.command, //修复初始化的指令
  426. cosResponse: val.cosResponse, //修复初始化结果
  427. rechargeId: val.rechargeId, //充值流水号
  428. };
  429. const options = {
  430. type: 2,
  431. data: data,
  432. method: "POST",
  433. showLoading: true,
  434. };
  435. return new Promise(async (resolve, reject) => {
  436. const res = await request(quanXf, options);
  437. const data = stringToJson(res.bizContent);
  438. resolve(data);
  439. }).catch((error) => {
  440. reject(error);
  441. });
  442. };
  443. /*圈存申请*/
  444. const quanApplyAction = (data) => {
  445. console.log("圈存申请data====", data, data.rechargeId)
  446. var form = {
  447. cardId: card.cardId,
  448. fee: state.fee,
  449. preBalance: card.money,
  450. tradeType: state.tradeType,
  451. command: data.command,
  452. cosResponse: data.cosResponse,
  453. orderId: state.orderNum,
  454. rechargeId: data.rechargeId,
  455. openId: getItem(StorageKeys.OpenId),
  456. accountId: state.accountId
  457. };
  458. const options = {
  459. type: 2,
  460. data: form,
  461. method: "POST",
  462. showLoading: true,
  463. };
  464. return new Promise(async (resolve, reject) => {
  465. const res = await request(quanApply, options);
  466. const data = stringToJson(res.bizContent);
  467. resolve(data);
  468. }).catch((error) => {
  469. reject(error);
  470. });
  471. };
  472. /*圈存确认*/
  473. const uanConfirmAction = (data : any) => {
  474. console.log("圈存确认进入");
  475. let cmdArr = data.command.split(",");
  476. console.log(cmdArr);
  477. transCmd(cmdArr, function (res : any) {
  478. console.log("圈存透传");
  479. console.log(res);
  480. var arraylenth = res.length;
  481. var status = res[arraylenth - 1].substring(
  482. res[arraylenth - 1].length - 4,
  483. res[arraylenth - 1].length
  484. );
  485. console.log("打印圈存确认指令状态");
  486. if (status === "9000") {
  487. var form = {
  488. command: data.command,
  489. cosResponse: res.toString(),
  490. rechargeId: data.rechargeId,
  491. paidAmount: state.fee,
  492. giftAmount: 0,
  493. tradeType: 12,
  494. consumeId: state.consumeId,
  495. accountId: state.accountId
  496. };
  497. const options = {
  498. type: 2,
  499. data: form,
  500. method: "POST",
  501. showLoading: true,
  502. };
  503. return new Promise(async () => {
  504. const res = await request(quanConfirm, options);
  505. const data = stringToJson(res.bizContent);
  506. console.log("data充值成功", data);
  507. // readCard()
  508. console.log("充值成功2222222")
  509. setTimeout(() => {
  510. msg("修复成功");
  511. navTo(`./result?cardId=${card.cardId}`)
  512. }, 2000)
  513. }).catch((error) => {
  514. console.log('输出内容', error)
  515. });
  516. }
  517. });
  518. };
  519. const uanConfirmSucessAction = (data) => {
  520. var form = {
  521. command: data.command,
  522. cosResponse: "9000",
  523. rechargeId: data.rechargeId,
  524. paidAmount: state.fee,
  525. giftAmount: 0,
  526. tradeType: 12,
  527. accountId: state.accountId
  528. };
  529. const options = {
  530. type: 2,
  531. data: form,
  532. method: "POST",
  533. showLoading: true,
  534. };
  535. return new Promise(async (resolve, reject) => {
  536. const res = await request(quanConfirm, options);
  537. const data = stringToJson(res.bizContent);
  538. resolve(data);
  539. console.log("uanConfirmSucessAction", data)
  540. }).catch((error) => {
  541. reject(error);
  542. });
  543. };
  544. /*充值检测*/
  545. const czCheckAction = () => {
  546. var form = {
  547. cardId: state.cardId,
  548. openId: getItem(StorageKeys.OpenId),
  549. };
  550. const options = {
  551. type: 2,
  552. data: form,
  553. method: "POST",
  554. showLoading: true,
  555. };
  556. return new Promise(async (resolve, reject) => {
  557. const res = await request(cardCzPayResultCheck, options);
  558. const data = stringToJson(res.bizContent);
  559. console.log("充值检测", data)
  560. resolve(data);
  561. }).catch((error) => {
  562. reject(error);
  563. });
  564. };
  565. /*充值申请*/
  566. const cardCzApplyAction = () => {
  567. var data = {
  568. cardId: state.cardId,
  569. openId: getItem(StorageKeys.OpenId),
  570. rechargeMoney: state.fee,
  571. };
  572. const options = {
  573. type: 2,
  574. data: data,
  575. method: "POST",
  576. showLoading: true,
  577. };
  578. return new Promise(async (resolve, reject) => {
  579. const res = await request(cardCzApply, options);
  580. const data = stringToJson(res.bizContent);
  581. resolve(data);
  582. }).catch((error) => {
  583. reject(error);
  584. });
  585. };
  586. //获取微信小程序openid
  587. const getOpenID = () => {
  588. uni.login({
  589. provider: "weixin",
  590. success: function (e) {
  591. getOpenid(e.code);
  592. },
  593. fail: function () {
  594. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  595. },
  596. });
  597. };
  598. const getOpenid = (code) => {
  599. const options = {
  600. type: 2,
  601. data: {
  602. "jsCode": code
  603. },
  604. method: "POST",
  605. showLoading: true,
  606. };
  607. // #ifdef MP-WEIXIN
  608. requestNew(getOpenId, options).then((res) => {
  609. const result = res;
  610. console.log("获取微信小程序openid", result);
  611. const openidData = stringToJson(result.data);
  612. state.openid = openidData.openid
  613. /*读卡*/
  614. getCardId(1);
  615. });
  616. // #endif
  617. }
  618. //掉起微信支付
  619. const wxPayment = () => {
  620. // #ifdef MP-WEIXIN
  621. const options = {
  622. type: 2,
  623. data: {
  624. openId: getItem(StorageKeys.OpenId),
  625. wxOpenId: state.openid,
  626. cardId: state.cardId,
  627. orderNum: state.orderNum,
  628. payConfigId: wechatPayConfigId,
  629. body: "储值卡充值",
  630. },
  631. method: "POST",
  632. showLoading: true,
  633. };
  634. request(cardCzPay, options).then((res) => {
  635. const data = stringToJson(res.bizContent);
  636. uni.requestPayment({
  637. provider: "wxpay",
  638. orderInfo: "",
  639. timeStamp: data.timestamp,
  640. nonceStr: data.noncestr,
  641. package: data.wxPackage ? data.wxPackage : "",
  642. signType: data.signType,
  643. paySign: data.sign,
  644. success: function () {
  645. //回调订单状态
  646. console.log("回调订单状态");
  647. checkOrder();
  648. },
  649. fail: function (err) {
  650. confirm(err, () => { }, "支付失败", false);
  651. },
  652. });
  653. });
  654. // #endif
  655. };
  656. //掉起支付宝支付
  657. const aliPayment = () => {
  658. // #ifdef MP-ALIPAY
  659. my.getAuthCode({
  660. scopes: 'auth_base',
  661. success: res => {
  662. const optionsUser = {
  663. type: 2,
  664. data: {
  665. payConfigId: aliPayConfigId,
  666. code: res.authCode
  667. },
  668. method: "POST",
  669. showLoading: true,
  670. };
  671. requestNew(obtainUserId, optionsUser).then((res) => {
  672. const data = res;
  673. const optionsali = {
  674. type: 2,
  675. data: {
  676. openId: getItem(StorageKeys.OpenId),
  677. wxOpenId: data.openId,
  678. cardId: state.cardId,
  679. orderNum: state.orderNum,
  680. payConfigId: "6a9a54123456578934edfre132b1234",
  681. body: "储值卡充值",
  682. },
  683. method: "POST",
  684. showLoading: true,
  685. };
  686. request(cardCzPay, optionsali).then((res) => {
  687. const data = stringToJson(res.bizContent);
  688. my.tradePay({
  689. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  690. tradeNO: data.tranPackage,
  691. success: res => {
  692. console.log("支付成功", res);
  693. checkOrder();
  694. },
  695. fail: res => {
  696. confirm(res, () => { }, "支付失败", false);
  697. },
  698. });
  699. });
  700. });
  701. },
  702. fail: err => {
  703. console.log('my.getAuthCode 调用失败', err)
  704. }
  705. });
  706. // #endif
  707. };
  708. //支付成功改变订单状态
  709. const checkOrder = () => {
  710. const options = {
  711. type: 2,
  712. data: {
  713. cardId: state.cardId,
  714. openId: getItem(StorageKeys.OpenId),
  715. orderNum: state.orderNum,
  716. },
  717. method: "POST",
  718. showLoading: true,
  719. };
  720. request(cardCzPayResult, options).then((res) => {
  721. const data = stringToJson(res.bizContent);
  722. if (data.tradeState === "SUCCESS") {
  723. getCardId();
  724. }
  725. console.log(data);
  726. });
  727. };
  728. const readCard = () => {
  729. let cmdArr = [
  730. cmd.HOME_DIRECTORY,
  731. //选择主目
  732. cmd.APPLICATION_DIRECTORY,
  733. //选择文件1001--DF01联网收费应用目录
  734. cmd.CMD_READBINARY,
  735. //15文件--卡片发行基本数据文件
  736. cmd.CMD_GETBALANCE,
  737. //钱包
  738. ];
  739. tools.showLoadingAlert("正在执行指令");
  740. transCmd(cmdArr, function (res : any) {
  741. tools.hideLoadingAlert();
  742. //10:写卡 20:写OBU
  743. let str = res[2].substring(res[2].length - 4, res[2].length);
  744. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  745. if (str == "9000" || str3 == "9000") {
  746. if (res[2].length > 86 || res[3] >= 12) {
  747. state.cardId = res[2].substring(20, 40); //卡号
  748. card.cardId = res[2].substring(20, 40); //卡号
  749. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  750. }
  751. }
  752. })
  753. }
  754. </script>
  755. <style>
  756. .balance {
  757. margin-left: 30rpx;
  758. font-size: 32rpx;
  759. color: #000;
  760. margin-bottom: 10rpx;
  761. }
  762. label {
  763. display: flex;
  764. justify-content: space-between;
  765. margin-top: 30rpx;
  766. }
  767. .button {
  768. height: 80rpx;
  769. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  770. border-radius: 40rpx;
  771. font-size: 32rpx;
  772. font-weight: 400;
  773. color: #ffffff !important;
  774. line-height: 80rpx;
  775. margin-top: 100rpx;
  776. width: 80%;
  777. }
  778. </style>