Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

recharge-two.vue 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. <template>
  2. <view class="wrapper">
  3. <view class="account">
  4. <image :src="`${$imgUrl}common/bg-recharge.png`" class="head-bg" mode="aspectFill"></image>
  5. <view class="account-text">
  6. <view class="balance">
  7. <text class="balance-tit">账户余额</text>
  8. <text class="balance-val">{{card.money/100}}元</text>
  9. </view>
  10. <view class="right-box">
  11. <view class="no">账户编号:000100</view>
  12. <view class="btn btn-record" @click="goRecord()">账户充值记录</view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup lang="ts">
  19. import {
  20. stringToJson
  21. } from "@/utils/network/encryption";
  22. import {
  23. onLoad,
  24. onShow
  25. } from "@dcloudio/uni-app";
  26. import {
  27. quanCheck,
  28. quanApply,
  29. quanXf,
  30. cardCzPayResultCheck,
  31. cardCzApply,
  32. cardCzPay,
  33. cardCzPayResult,
  34. cardCzXFCheck,
  35. quanConfirm,
  36. wechatAppID,
  37. wechatPayConfigId,
  38. wechatSecret,
  39. aliPayConfigId,
  40. obtainUserId,
  41. getOpenidApi
  42. } from "@/utils/network/api.js";
  43. import {
  44. request
  45. } from "@/utils/network/request.js";
  46. import {
  47. reactive
  48. } from "vue";
  49. import {
  50. navTo
  51. } from "@/utils/utils"
  52. import {
  53. msg
  54. } from "@/utils/utils";
  55. import {
  56. getItem,
  57. StorageKeys,
  58. setItem
  59. } from "@/utils/storage";
  60. const datas = require("../../../static/etcUtil/datas.js");
  61. const bluetoothUtil = require("../../../static/etcUtil/index.js");
  62. const cmd = require("../../../static/etcUtil/cmdConfig.js");
  63. const tools = require("../../../static/etcUtil/tools.js");
  64. const NFCAPI = require('../../../static/nfc/NFCAPI.js');
  65. const state = reactive({
  66. transWayTypeShow: false,
  67. transWayTypeList: [{
  68. label: "蓝牙",
  69. value: "blu",
  70. }, {
  71. label: "NFC",
  72. value: "nfc",
  73. }
  74. ],
  75. isShowBlue: false,
  76. moneryArray: [{
  77. name: '50元',
  78. value: 50
  79. }, {
  80. name: '100元',
  81. value: 100
  82. }, {
  83. name: '200元',
  84. value: 200
  85. }, {
  86. name: '300元',
  87. value: 300
  88. }, {
  89. name: '500元',
  90. value: 500
  91. }, {
  92. name: '1000元',
  93. value: 1000
  94. }],
  95. tableIndex: 0,
  96. openid: "",
  97. connectSuccess: undefined,
  98. fee: 5000,
  99. money: 50,
  100. orderNum: "",
  101. transWayName: "蓝牙",
  102. transWay: "blu", //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  103. cardId: "", //卡号 需要传参
  104. mockpreBalance: 2000, //fix:模拟余额 目前没有检测状态接口,第一次会模拟圈存检测来检测状态
  105. show: false,
  106. items: [{
  107. value: '0',
  108. name: '微信',
  109. checked: 'true'
  110. },
  111. {
  112. value: '1',
  113. name: '对公账户'
  114. }
  115. ],
  116. current: 0,
  117. tradeType: 14,
  118. payMoney: 0, //0 1直接走支付 0就是修复
  119. });
  120. const selectConfirm = (item : any) => {
  121. state.transWayName = item[0].label
  122. state.transWay = item[0].value
  123. };
  124. //读卡信息
  125. const card : any = reactive({
  126. cardId: "",
  127. netId: "",
  128. cardType: "",
  129. startTime: "",
  130. endTime: "",
  131. userName: "",
  132. idNum: "",
  133. vehiclePlate: "",
  134. vehiclePlateColor: "",
  135. color: "",
  136. version: "",
  137. type: "",
  138. favourable: "",
  139. money: undefined,
  140. v_userType: "",
  141. });
  142. onLoad((option) => {
  143. console.log("来了=====")
  144. /*获取openId 用途:(用户支付)*/
  145. // #ifdef MP-WEIXIN
  146. getOpenID();/*传参*/
  147. // #endif
  148. console.log("开始option", option)
  149. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  150. state.connectSuccess = option.connectSuccess;
  151. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  152. if (option.rechargeMoney) { //圈存金额
  153. state.fee = option.rechargeMoney
  154. state.money = option.rechargeMoney / 100
  155. }
  156. if (option.orderNum) { //圈存金额
  157. state.orderNum = option.orderNum
  158. state.payMoney = Number(option.payMoney)
  159. }
  160. console.log("option.orderNum", option, option.orderNum)
  161. //跳转过来走圈存流程
  162. // connectSuccess 2 从选择方式进来去圈存检测 1 只读卡
  163. // #ifdef MP-ALIPAY
  164. /*读卡*/
  165. getCardId(1);
  166. // #endif
  167. });
  168. function radioChange(evt) {
  169. console.log('输出内容', evt)
  170. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  171. }
  172. function go(money) {
  173. let content = ""
  174. // if (money) {
  175. state.fee = money * 100
  176. //走蓝牙进行修复
  177. quanCheckActionTrue().then((val : any) => {
  178. console.log("圈存检测val", val)
  179. //如果 圈存检测正常
  180. if (val.chargeStatus === 1) {
  181. console.log(`进行充值检测`);
  182. czCheckAction().then((checkResult : any) => {
  183. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  184. if (checkResult.orders && checkResult.orders.length > 0) {
  185. //拿到订单,存起来
  186. state.orderNum = checkResult.orders[0].orderNum;
  187. // 检测用户是否存在有半条流水
  188. getCardId()
  189. } else {
  190. console.log('没有可修复的流水')
  191. }
  192. });
  193. } else {
  194. // 检测用户是否存在有半条流水
  195. getCardId()
  196. }
  197. });
  198. console.log("state.isShowBlue", state.isShowBlue)
  199. }
  200. const tableIndexAction = (val : any) => {
  201. state.tableIndex = val
  202. state.money = state.moneryArray[val].value
  203. }
  204. /*点击充值按钮*/
  205. const rechargeAction = () => {
  206. state.fee = state.money * 100; //元换成分
  207. /*进行圈存检测,此处检测仅为校验圈存状态来决定去哪里*/
  208. console.log("进行圈存检测");
  209. quanCheckActionTrue().then((val : any) => {
  210. console.log("圈存检测接口返回", val)
  211. //如果 圈存检测正常
  212. if (val.chargeStatus === 1) {
  213. console.log(`进行充值检测`);
  214. czCheckAction().then((checkResult : any) => {
  215. console.log("进行充值检测", checkResult)
  216. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  217. if (checkResult.orders && checkResult.orders.length > 0) {
  218. state.fee = checkResult.orders[0]['rechargeMoney']
  219. state.money = checkResult.orders[0]['rechargeMoney'] / 100
  220. //拿到订单,存起来
  221. state.orderNum = checkResult.orders[0].orderNum;
  222. //链接蓝牙
  223. go(state.money)
  224. } else {
  225. cardCzApplyAction().then((applyResult : any) => {
  226. //拿到订单 存起来
  227. state.orderNum = applyResult.orderNum;
  228. //如果订单没有支付 走支付
  229. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  230. //走支付
  231. console.log("走支付");
  232. // #ifdef MP-WEIXIN
  233. wxPayment();
  234. // #endif
  235. // #ifdef MP-ALIPAY
  236. aliPayment()
  237. // #endif
  238. }
  239. });
  240. }
  241. });
  242. } else {
  243. //走蓝牙进行修复
  244. // 圈存检测异常,继续上次圈存 chargeStatus==2
  245. let fixFee = val.fixFee / 100
  246. console.log("fixFee", fixFee)
  247. go(fixFee)
  248. }
  249. });
  250. };
  251. /*读卡*/
  252. const getCardId = (readCard) => {
  253. console.log("======获取卡信息======");
  254. let cmdArr = [
  255. cmd.HOME_DIRECTORY,
  256. //选择主目
  257. cmd.APPLICATION_DIRECTORY,
  258. //选择文件1001--DF01联网收费应用目录
  259. cmd.CMD_READBINARY,
  260. //15文件--卡片发行基本数据文件
  261. cmd.CMD_GETBALANCE,
  262. //钱包
  263. ];
  264. tools.showLoadingAlert("正在执行指令");
  265. transCmd(cmdArr, function (res : any) {
  266. if (readCard == 1) {
  267. // 只读卡号
  268. getCardIdReturnReadCard(res)
  269. } else {
  270. getCardIdReturn(res);
  271. }
  272. })
  273. };
  274. function getCardIdReturnReadCard(res : any) {
  275. tools.hideLoadingAlert();
  276. //10:写卡 20:写OBU
  277. let str = res[2].substring(res[2].length - 4, res[2].length);
  278. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  279. if (str == "9000" || str3 == "9000") {
  280. if (res[2].length > 86 || res[3] >= 12) {
  281. state.cardId = res[2].substring(20, 40); //卡号
  282. card.cardId = res[2].substring(20, 40); //卡号
  283. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  284. console.log("======卡信息======", card, state.cardId, state.orderNum, !state.orderNum);
  285. if (state.payMoney) {
  286. // #ifdef MP-WEIXIN
  287. wxPayment();
  288. // #endif
  289. // #ifdef MP-ALIPAY
  290. aliPayment()
  291. // #endif
  292. console.log("去支付11111", state.payMoney)
  293. } else {
  294. quanCheckActionTrue().then((val : any) => {
  295. console.log("圈存检测val", val)
  296. //如果 圈存检测正常
  297. if (val.chargeStatus === 1) {
  298. console.log(`进行充值检测`);
  299. czCheckAction().then((checkResult : any) => {
  300. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  301. if (checkResult.orders && checkResult.orders.length > 0) {
  302. //拿到订单,存起来
  303. state.orderNum = checkResult.orders[0].orderNum;
  304. // 检测用户是否存在有半条流水
  305. rechargeAction()
  306. } else {
  307. console.log('没有可修复的流水')
  308. }
  309. });
  310. } else {
  311. // 检测用户是否存在有半条流水
  312. }
  313. });
  314. }
  315. } else {
  316. console.error("CMD_READBINARY指令长度不符" + res[2]);
  317. tools.hideLoadingAlert();
  318. }
  319. }
  320. console.error("CMD_READBINARY指令长度不符" + res[2]);
  321. tools.hideLoadingAlert();
  322. }
  323. function getCardIdReturn(res : any) {
  324. tools.hideLoadingAlert();
  325. //10:写卡 20:写OBU
  326. let str = res[2].substring(res[2].length - 4, res[2].length);
  327. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  328. if (str == "9000" || str3 == "9000") {
  329. if (res[2].length > 86 || res[3] >= 12) {
  330. state.cardId = res[2].substring(20, 40); //卡号
  331. card.cardId = res[2].substring(20, 40); //卡号
  332. card.startTime = res[2].substring(40, 48);
  333. card.endTime = res[2].substring(48, 56);
  334. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  335. card.netId = res[2].substring(20, 24);
  336. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  337. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  338. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  339. console.log("======卡信息======", card, card.money);
  340. // if (card.cardId !== state.cardId) {
  341. // msg("设备卡信息与当前充值卡号不匹配,请核对卡号");
  342. // return;
  343. // }
  344. quanCheckActionTrue().then((val) => {
  345. checkQuanCengEvent(val);
  346. });
  347. } else {
  348. console.error("CMD_READBINARY指令长度不符" + res[2]);
  349. tools.hideLoadingAlert();
  350. }
  351. }
  352. console.error("CMD_READBINARY指令长度不符" + res[2]);
  353. tools.hideLoadingAlert();
  354. }
  355. const checkQuanCengEvent = (val : any) => {
  356. if (val.chargeStatus === 1) {
  357. let cmdArr = val.command.split(",");
  358. uni.showLoading({
  359. title: "写入中",
  360. });
  361. transCmd(cmdArr, function (res : any) {
  362. let response = res.toString();
  363. var dic = {
  364. command: val.command,
  365. cosResponse: response,
  366. };
  367. uni.hideLoading();
  368. quanApplyAction(dic).then((value : any) => {
  369. console.log("圈存申请完后的结果");
  370. console.log(value.commandType, value);
  371. //圈存初始化验证通过 , 进行圈存
  372. if (value.commandType === 2) {
  373. uanConfirmAction(value);
  374. } else {
  375. console.log("第二次70", value)
  376. let cmdArr = value.command.split(",");
  377. uni.showLoading({
  378. title: "写入中",
  379. });
  380. transCmd(cmdArr, function (res : any) {
  381. let response = res.toString();
  382. var dic = {
  383. command: val.command,
  384. cosResponse: response,
  385. };
  386. uni.hideLoading();
  387. quanApplyAction(dic).then((values) => {
  388. console.log("圈存申请完后的结果");
  389. uanConfirmAction(values);
  390. });
  391. })
  392. }
  393. });
  394. });
  395. } else {
  396. let cmdArr = val.command.split(",");
  397. uni.showLoading({
  398. title: "写入中",
  399. });
  400. transCmd(cmdArr, function (res : any) {
  401. var status = res[1].substring(res[1].length - 4, res[1].length);
  402. console.log("打印状态");
  403. console.log(status);
  404. if (status === "9000") {
  405. console.log("修复指令入参");
  406. let response = res.toString();
  407. var dic = {
  408. command: val.command,
  409. cosResponse: response,
  410. rechargeId: val.rechargeId,
  411. };
  412. quanFixAction(dic).then((value : any) => {
  413. state.orderNum = value.orderId
  414. state.tradeType = value.tradeType
  415. console.log(value);
  416. console.log("修复结果返回");
  417. var fixStatus = value.fixStatus;
  418. //圈存修复COS指令Response信息不足,重新进行修复初始化
  419. if (fixStatus === 3) {
  420. let xfcmdArr = value.command.split(",");
  421. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  422. var status = resValueData[1].substring(
  423. resValueData[1].length - 4,
  424. resValueData[1].length
  425. );
  426. console.log("打印状态");
  427. console.log(status);
  428. if (status === "9000") {
  429. console.log(resValueData);
  430. var valueResponse = resValueData.toString();
  431. console.log(response);
  432. var applyDic = {
  433. command: value.command,
  434. cosResponse: valueResponse,
  435. rechargeId: value.rechargeId,
  436. };
  437. console.log("消费成功");
  438. quanApplyAction(applyDic).then((applyValue) => {
  439. uanConfirmAction(applyValue);
  440. });
  441. }
  442. });
  443. } else if (fixStatus === 2) {
  444. uanConfirmSucessAction(value).then((confirmResult) => {
  445. console.log("充值成功2222222")
  446. readCard();
  447. setTimeout(() => {
  448. msg("修复成功");
  449. navTo(`./result`)
  450. }, 2000)
  451. });
  452. } else if (fixStatus === 1) {
  453. quanCheckActionTrue().then((val) => {
  454. checkQuanCengEvent(val);
  455. });
  456. }
  457. });
  458. uni.hideLoading();
  459. }
  460. });
  461. }
  462. };
  463. /*透传*/
  464. const transCmd = (cmd : any, click : any) => {
  465. if (state.transWay == 'blu') {
  466. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  467. click(res);
  468. });
  469. } else {
  470. //nfc透传
  471. NFCAPI.transCmd(cmd, function (res : any) {
  472. tools.hideLoadingAlert();
  473. if (res.code == 0) {
  474. click(res.data);
  475. } else {
  476. //透传失败返回
  477. tools.alertF(res.msg);
  478. }
  479. });
  480. }
  481. };
  482. const quanCheckActionTrue = () => {
  483. console.log("进行真实圈存检测");
  484. var data = {
  485. cardId: card.cardId,
  486. fee: state.fee,
  487. preBalance: card.money,
  488. tradeType: 14,
  489. };
  490. const options = {
  491. type: 2,
  492. data: data,
  493. method: "POST",
  494. showLoading: true,
  495. };
  496. return new Promise(async (resolve, reject) => {
  497. const res = await request(quanCheck, options);
  498. const data = stringToJson(res.bizContent);
  499. resolve(data);
  500. }).catch((error) => {
  501. reject(error);
  502. });
  503. };
  504. /*充值消费*/
  505. const cardCzXFCheckAction = () => {
  506. var data = {
  507. cardId: card.cardId, //修复初始化的指令
  508. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  509. orderNum: state.orderNum, //充值流水号
  510. };
  511. const options = {
  512. type: 2,
  513. data: data,
  514. method: "POST",
  515. showLoading: true,
  516. };
  517. return new Promise(async (resolve, reject) => {
  518. const res = await request(cardCzXFCheck, options);
  519. const data = stringToJson(res.bizContent);
  520. resolve(data);
  521. }).catch((error) => {
  522. reject(error);
  523. });
  524. };
  525. /*圈存修复*/
  526. const quanFixAction = (val) => {
  527. var data = {
  528. command: val.command, //修复初始化的指令
  529. cosResponse: val.cosResponse, //修复初始化结果
  530. rechargeId: val.rechargeId, //充值流水号
  531. };
  532. const options = {
  533. type: 2,
  534. data: data,
  535. method: "POST",
  536. showLoading: true,
  537. };
  538. return new Promise(async (resolve, reject) => {
  539. const res = await request(quanXf, options);
  540. const data = stringToJson(res.bizContent);
  541. resolve(data);
  542. }).catch((error) => {
  543. reject(error);
  544. });
  545. };
  546. /*圈存申请*/
  547. const quanApplyAction = (data) => {
  548. console.log("圈存申请data====", data, data.rechargeId)
  549. var form = {
  550. cardId: card.cardId,
  551. fee: state.fee,
  552. preBalance: card.money,
  553. tradeType: state.tradeType,
  554. command: data.command,
  555. cosResponse: data.cosResponse,
  556. orderId: state.orderNum,
  557. rechargeId: data.rechargeId,
  558. openId: getItem(StorageKeys.OpenId)
  559. };
  560. const options = {
  561. type: 2,
  562. data: form,
  563. method: "POST",
  564. showLoading: true,
  565. };
  566. return new Promise(async (resolve, reject) => {
  567. const res = await request(quanApply, options);
  568. const data = stringToJson(res.bizContent);
  569. resolve(data);
  570. }).catch((error) => {
  571. reject(error);
  572. });
  573. };
  574. /*圈存确认*/
  575. const uanConfirmAction = (data : any) => {
  576. console.log("圈存确认进入");
  577. let cmdArr = data.command.split(",");
  578. console.log(cmdArr);
  579. transCmd(cmdArr, function (res : any) {
  580. console.log("圈存透传");
  581. console.log(res);
  582. var arraylenth = res.length;
  583. var status = res[arraylenth - 1].substring(
  584. res[arraylenth - 1].length - 4,
  585. res[arraylenth - 1].length
  586. );
  587. console.log("打印圈存确认指令状态");
  588. if (status === "9000") {
  589. var form = {
  590. command: data.command,
  591. cosResponse: res.toString(),
  592. rechargeId: data.rechargeId,
  593. paidAmount: state.fee,
  594. giftAmount: 0,
  595. };
  596. const options = {
  597. type: 2,
  598. data: form,
  599. method: "POST",
  600. showLoading: true,
  601. };
  602. return new Promise(async () => {
  603. const res = await request(quanConfirm, options);
  604. const data = stringToJson(res.bizContent);
  605. console.log("data充值成功", data);
  606. readCard()
  607. console.log("充值成功2222222")
  608. setTimeout(() => {
  609. msg("修复成功");
  610. navTo(`./result`)
  611. }, 2000)
  612. }).catch((error) => {
  613. console.log('输出内容', error)
  614. });
  615. }
  616. });
  617. };
  618. const uanConfirmSucessAction = (data) => {
  619. var form = {
  620. command: data.command,
  621. cosResponse: "9000",
  622. rechargeId: data.rechargeId,
  623. paidAmount: state.fee,
  624. giftAmount: 0,
  625. };
  626. const options = {
  627. type: 2,
  628. data: form,
  629. method: "POST",
  630. showLoading: true,
  631. };
  632. return new Promise(async (resolve, reject) => {
  633. const res = await request(quanConfirm, options);
  634. const data = stringToJson(res.bizContent);
  635. resolve(data);
  636. console.log("uanConfirmSucessAction", data)
  637. }).catch((error) => {
  638. reject(error);
  639. });
  640. };
  641. /*充值检测*/
  642. const czCheckAction = () => {
  643. var form = {
  644. cardId: state.cardId,
  645. openId: getItem(StorageKeys.OpenId),
  646. };
  647. const options = {
  648. type: 2,
  649. data: form,
  650. method: "POST",
  651. showLoading: true,
  652. };
  653. return new Promise(async (resolve, reject) => {
  654. const res = await request(cardCzPayResultCheck, options);
  655. const data = stringToJson(res.bizContent);
  656. console.log("充值检测", data)
  657. resolve(data);
  658. }).catch((error) => {
  659. reject(error);
  660. });
  661. };
  662. /*充值申请*/
  663. const cardCzApplyAction = () => {
  664. var data = {
  665. cardId: state.cardId,
  666. openId: getItem(StorageKeys.OpenId),
  667. rechargeMoney: state.fee,
  668. };
  669. const options = {
  670. type: 2,
  671. data: data,
  672. method: "POST",
  673. showLoading: true,
  674. };
  675. return new Promise(async (resolve, reject) => {
  676. const res = await request(cardCzApply, options);
  677. const data = stringToJson(res.bizContent);
  678. resolve(data);
  679. }).catch((error) => {
  680. reject(error);
  681. });
  682. };
  683. //获取微信小程序openid
  684. const getOpenID = () => {
  685. uni.login({
  686. provider: "weixin",
  687. success: function (e) {
  688. getOpenid(e.code);
  689. },
  690. fail: function () {
  691. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  692. },
  693. });
  694. };
  695. const getOpenid = (code) => {
  696. const options = {
  697. type: 2,
  698. data: {
  699. "jsCode": code
  700. },
  701. method: "POST",
  702. showLoading: true,
  703. };
  704. // #ifdef MP-WEIXIN
  705. request(getOpenidApi, options).then((res) => {
  706. const result = stringToJson(res.bizContent);
  707. console.log("获取微信小程序openid", result);
  708. const openidData = stringToJson(result.data);
  709. // setItem("QYorder", result.data);
  710. state.openid = openidData.openid
  711. /*读卡*/
  712. getCardId(1);
  713. });
  714. // #endif
  715. }
  716. //掉起微信支付
  717. const wxPayment = () => {
  718. // #ifdef MP-WEIXIN
  719. const options = {
  720. type: 2,
  721. data: {
  722. openId: getItem(StorageKeys.OpenId),
  723. wxOpenId: state.openid,
  724. cardId: state.cardId,
  725. orderNum: state.orderNum,
  726. payConfigId: wechatPayConfigId,
  727. body: "储值卡充值",
  728. },
  729. method: "POST",
  730. showLoading: true,
  731. };
  732. request(cardCzPay, options).then((res) => {
  733. const data = stringToJson(res.bizContent);
  734. uni.requestPayment({
  735. provider: "wxpay",
  736. orderInfo: "",
  737. timeStamp: data.timestamp,
  738. nonceStr: data.noncestr,
  739. package: data.wxPackage ? data.wxPackage : "",
  740. signType: data.signType,
  741. paySign: data.sign,
  742. success: function () {
  743. //回调订单状态
  744. console.log("回调订单状态");
  745. checkOrder();
  746. },
  747. fail: function (err) {
  748. confirm(err, () => { }, "支付失败", false);
  749. },
  750. });
  751. });
  752. // #endif
  753. };
  754. //掉起支付宝支付
  755. const aliPayment = () => {
  756. // #ifdef MP-ALIPAY
  757. my.getAuthCode({
  758. scopes: 'auth_base',
  759. success: res => {
  760. const optionsUser = {
  761. type: 2,
  762. data: {
  763. payConfigId: aliPayConfigId,
  764. code: res.authCode
  765. },
  766. method: "POST",
  767. showLoading: true,
  768. };
  769. request(obtainUserId, optionsUser).then((res) => {
  770. const data = stringToJson(res.bizContent);
  771. const optionsali = {
  772. type: 2,
  773. data: {
  774. openId: getItem(StorageKeys.OpenId),
  775. wxOpenId: data.openId,
  776. cardId: state.cardId,
  777. orderNum: state.orderNum,
  778. payConfigId: "6a9a54123456578934edfre132b1234",
  779. body: "储值卡充值",
  780. },
  781. method: "POST",
  782. showLoading: true,
  783. };
  784. request(cardCzPay, optionsali).then((res) => {
  785. const data = stringToJson(res.bizContent);
  786. my.tradePay({
  787. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  788. tradeNO: data.tranPackage,
  789. success: res => {
  790. console.log("支付成功", res);
  791. checkOrder();
  792. },
  793. fail: res => {
  794. confirm(res, () => { }, "支付失败", false);
  795. },
  796. });
  797. });
  798. });
  799. },
  800. fail: err => {
  801. console.log('my.getAuthCode 调用失败', err)
  802. }
  803. });
  804. // #endif
  805. };
  806. //支付成功改变订单状态
  807. const checkOrder = () => {
  808. const options = {
  809. type: 2,
  810. data: {
  811. cardId: state.cardId,
  812. openId: getItem(StorageKeys.OpenId),
  813. orderNum: state.orderNum,
  814. },
  815. method: "POST",
  816. showLoading: true,
  817. };
  818. request(cardCzPayResult, options).then((res) => {
  819. const data = stringToJson(res.bizContent);
  820. if (data.tradeState === "SUCCESS") {
  821. getCardId();
  822. }
  823. console.log(data);
  824. });
  825. };
  826. const goRecord = () => {
  827. uni.navigateTo({
  828. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  829. })
  830. }
  831. // 校验金额输入框
  832. const checkNum = (event) => {
  833. let sNum = event.target.value.toString(); //先转换成字符串类
  834. if (sNum.indexOf('.') == 0) {//第一位就是 .
  835. console.log('first str is .')
  836. sNum = '0' + sNum
  837. }
  838. sNum = sNum.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
  839. sNum = sNum.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
  840. sNum = sNum.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  841. sNum = sNum.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
  842. //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
  843. if (sNum.indexOf(".") < 0 && sNum != "") {
  844. sNum = parseFloat(sNum);
  845. }
  846. console.log('输入的值1', sNum)
  847. setTimeout(() => {
  848. state.money = sNum
  849. }, 20)
  850. }
  851. const readCard = () => {
  852. let cmdArr = [
  853. cmd.HOME_DIRECTORY,
  854. //选择主目
  855. cmd.APPLICATION_DIRECTORY,
  856. //选择文件1001--DF01联网收费应用目录
  857. cmd.CMD_READBINARY,
  858. //15文件--卡片发行基本数据文件
  859. cmd.CMD_GETBALANCE,
  860. //钱包
  861. ];
  862. tools.showLoadingAlert("正在执行指令");
  863. transCmd(cmdArr, function (res : any) {
  864. tools.hideLoadingAlert();
  865. //10:写卡 20:写OBU
  866. let str = res[2].substring(res[2].length - 4, res[2].length);
  867. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  868. if (str == "9000" || str3 == "9000") {
  869. if (res[2].length > 86 || res[3] >= 12) {
  870. state.cardId = res[2].substring(20, 40); //卡号
  871. card.cardId = res[2].substring(20, 40); //卡号
  872. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  873. }
  874. }
  875. })
  876. }
  877. </script>
  878. <style>
  879. .account {
  880. height: 224rpx;
  881. width: 690rpx;
  882. margin: 30rpx;
  883. position: relative;
  884. }
  885. .account .account-text {
  886. display: flex;
  887. justify-content: space-between;
  888. padding: 20rpx 50rpx;
  889. height: 100%;
  890. }
  891. .account .balance {
  892. display: flex;
  893. flex-direction: column;
  894. justify-content: center;
  895. align-items: flex-start;
  896. color: #ffffff;
  897. }
  898. .account .balance-tit {
  899. font-size: 26rpx;
  900. margin-bottom: 10rpx;
  901. }
  902. .account .balance-val {
  903. font-size: 56rpx;
  904. }
  905. .account .right-box {
  906. display: flex;
  907. flex-direction: column;
  908. justify-content: flex-start;
  909. align-items: flex-end;
  910. }
  911. .account .right-box .no {
  912. font-size: 26rpx;
  913. color: #ffffff;
  914. }
  915. .account .right-box .btn {
  916. font-size: 26rpx;
  917. padding: 0 20rpx;
  918. box-sizing: border-box;
  919. height: 42rpx;
  920. line-height: 42rpx;
  921. color: #28d20f;
  922. background: #ffffff;
  923. border-radius: 21rpx;
  924. display: inline-block;
  925. margin-top: 18rpx;
  926. }
  927. .account .head-bg {
  928. width: 690rpx;
  929. height: 224rpx;
  930. position: absolute;
  931. left: 0;
  932. top: 0;
  933. z-index: -99;
  934. }
  935. .input-box {
  936. display: flex;
  937. flex-direction: column;
  938. justify-content: center;
  939. align-items: center;
  940. padding: 20rpx 0;
  941. }
  942. .input-box .input {
  943. width: 430rpx;
  944. height: 98rpx;
  945. line-height: 98rpx;
  946. background: #f8f8f8;
  947. border: 1px solid #999999;
  948. border-radius: 6rpx;
  949. font-size: 30rpx;
  950. text-align: center;
  951. }
  952. .input-box .tips {
  953. color: #666666;
  954. font-size: 26rpx;
  955. margin-top: 18rpx;
  956. }
  957. .tabs {}
  958. .tabs .tab-tit {
  959. font-size: 30rpx;
  960. color: #333;
  961. padding: 45rpx 0 22rpx 30rpx;
  962. }
  963. .tabs .tab {
  964. display: flex;
  965. flex-wrap: wrap;
  966. justify-content: space-evenly;
  967. }
  968. .tabs .tab .item {
  969. width: 210rpx;
  970. height: 100rpx;
  971. background: #f6fff7;
  972. border: 1px solid #dcdde1;
  973. box-sizing: border-box;
  974. line-height: 100rpx;
  975. border-radius: 6rpx;
  976. text-align: center;
  977. margin-bottom: 24rpx;
  978. color: #333333;
  979. font-size: 32rpx;
  980. }
  981. .tabs .tab .item.active {
  982. border: 1px solid #24cc49;
  983. color: #24cc49;
  984. }
  985. .btn-primary {
  986. width: 670rpx;
  987. height: 80rpx;
  988. line-height: 80rpx;
  989. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  990. border-radius: 40rpx;
  991. font-size: 32rpx;
  992. color: #ffffff;
  993. margin: 200rpx 40rpx 0;
  994. text-align: center;
  995. }
  996. .uni-list {
  997. padding: 120rpx 10rpx 0 10rpx;
  998. font-size: 34rpx;
  999. }
  1000. label {
  1001. display: flex;
  1002. justify-content: space-between;
  1003. margin-top: 30rpx;
  1004. }
  1005. </style>