Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

recharge.vue 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <template>
  2. <view class="wrapper">
  3. <view class="account">
  4. <image :src="`${$imgUrl}common/bg-recharge.png`" class="head-bg"></image>
  5. <view class="account-text">
  6. <view class="balance">
  7. <!-- <text class="balance-tit">账户余额</text> -->
  8. <!-- <text class="balance-val">20.00元</text> -->
  9. </view>
  10. <view class="right-box">
  11. <view class="no">账户编号:000100</view>
  12. <view class="btn btn-record">账户充值记录</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="input-box">
  17. <input placeholder="请输入金额" class="input" />
  18. <view class="tips">最低充值金额不小于10元</view>
  19. </view>
  20. <view class="tabs">
  21. <view class="tab-tit">在线充值</view>
  22. <view class="tab">
  23. <view class="item">50元</view>
  24. <view class="item active">100元</view>
  25. <view class="item">200元</view>
  26. <view class="item">300元</view>
  27. <view class="item">500元</view>
  28. <view class="item">1000元</view>
  29. </view>
  30. </view>
  31. <view class="btn btn-primary" @click="rechargeAction">立即充值</view>
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import { stringToJson } from "@/utils/network/encryption";
  36. import { onLoad, onShow } from "@dcloudio/uni-app";
  37. import {
  38. quanCheck,
  39. quanApply,
  40. quanXf,
  41. cardCzPayResultCheck,
  42. cardCzApply,
  43. cardCzPay,
  44. cardCzPayResult,
  45. cardCzXFCheck,
  46. quanConfirm,
  47. wechatAppID,
  48. wechatPayConfigId,
  49. wechatSecret,
  50. } from "@/utils/network/api.js";
  51. import { request } from "@/utils/network/request.js";
  52. import { reactive } from "vue";
  53. import { msg } from "@/utils/utils";
  54. import { getItem, StorageKeys, setItem } 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 state = reactive({
  60. openid: "",
  61. connectSuccess: undefined,
  62. fee: 1,
  63. orderNum: "",
  64. cardId: "", //卡号 需要传参
  65. mockpreBalance: 2000, //fix:模拟余额 目前没有检测状态接口,第一次会模拟圈层检测来检测状态
  66. });
  67. const card = reactive({
  68. cardId: "",
  69. netId: "",
  70. cardType: "",
  71. startTime: "",
  72. endTime: "",
  73. userName: "",
  74. idNum: "",
  75. vehiclePlate: "",
  76. vehiclePlateColor: "",
  77. color: "",
  78. version: "",
  79. type: "",
  80. favourable: "",
  81. money: undefined,
  82. v_userType: "",
  83. });
  84. onLoad((option) => {
  85. /*获取openId 用途:(用户支付)*/
  86. getOpenID();
  87. /*传参*/
  88. state.cardId = option.cardId;
  89. console.log(state.cardId);
  90. console.log("888888888");
  91. state.connectSuccess = option.connectSuccess;
  92. state.orderNum = getItem("orderNum");
  93. if (state.connectSuccess === "1") {
  94. /*读卡*/
  95. getCardId();
  96. }
  97. });
  98. /*点击充值按钮*/
  99. const rechargeAction = () => {
  100. /*进行圈层检测,此处检测仅为校验圈层状态来决定去哪里*/
  101. console.log("进行圈层检测");
  102. quanCheckAction().then((val: any) => {
  103. //如果 圈层检测正常
  104. if (val.chargeStatus === 1) {
  105. console.log(`进行充值检测`);
  106. czCheckAction().then((checkResult: any) => {
  107. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  108. if (checkResult.orders && checkResult.orders.length > 0) {
  109. //拿到订单,存起来
  110. state.orderNum = checkResult.orders[0].orderNum;
  111. setItem("orderNum", state.orderNum);
  112. //链接蓝牙
  113. uni.navigateTo({
  114. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}`,
  115. });
  116. } else {
  117. console.log(`进行充值申请`);
  118. cardCzApplyAction().then((applyResult: any) => {
  119. //拿到订单 存起来
  120. state.orderNum = applyResult.orderNum;
  121. setItem("orderNum", state.orderNum);
  122. //如果订单没有支付 走支付
  123. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  124. //走支付
  125. console.log("走支付");
  126. wxPayment();
  127. }
  128. });
  129. }
  130. });
  131. } else {
  132. //走蓝牙进行修复
  133. uni.navigateTo({
  134. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}`,
  135. });
  136. }
  137. });
  138. };
  139. /*读卡*/
  140. const getCardId = () => {
  141. console.log("======获取卡信息======");
  142. let cmdArr = [
  143. cmd.HOME_DIRECTORY,
  144. //选择主目
  145. cmd.APPLICATION_DIRECTORY,
  146. //选择文件1001--DF01联网收费应用目录
  147. cmd.CMD_READBINARY,
  148. //15文件--卡片发行基本数据文件
  149. cmd.CMD_GETBALANCE,
  150. //钱包
  151. ];
  152. tools.showLoadingAlert("正在执行指令");
  153. bluetoothUtil.transCmd(cmdArr, "10", function (res) {
  154. tools.hideLoadingAlert();
  155. //10:写卡 20:写OBU
  156. let str = res[2].substring(res[2].length - 4, res[2].length);
  157. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  158. if (str == "9000" || str3 == "9000") {
  159. if (res[2].length > 86 || res[3] >= 12) {
  160. card.cardId = res[2].substring(20, 40); //卡号
  161. card.startTime = res[2].substring(40, 48);
  162. card.endTime = res[2].substring(48, 56);
  163. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  164. card.netId = res[2].substring(20, 24);
  165. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  166. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  167. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  168. console.log("======卡信息======", card);
  169. if (card.cardId !== state.cardId) {
  170. msg("设备卡信息与当前充值卡号不匹配,请核对卡号");
  171. return;
  172. }
  173. quanCheckActionTrue().then((val) => {
  174. checkQuanCengEvent(val);
  175. });
  176. } else {
  177. console.error("CMD_READBINARY指令长度不符" + res[2]);
  178. tools.hideLoadingAlert();
  179. }
  180. }
  181. console.error("CMD_READBINARY指令长度不符" + res[2]);
  182. tools.hideLoadingAlert();
  183. });
  184. };
  185. const checkQuanCengEvent = (val: any) => {
  186. if (val.chargeStatus === 1) {
  187. let cmdArr = val.command.split(",");
  188. uni.showLoading({
  189. title: "写入中",
  190. });
  191. bluetoothUtil.transCmd(cmdArr, "10", function (res) {
  192. let response = res.toString();
  193. var dic = {
  194. command: val.command,
  195. cosResponse: response,
  196. };
  197. uni.hideLoading();
  198. cardCzXFCheckAction().then((xfRes) => {
  199. quanApplyAction(dic).then((value) => {
  200. console.log("圈层申请完后的结果");
  201. console.log(value);
  202. //圈存初始化验证通过 , 进行圈存
  203. if (value.commandType === 2) {
  204. uanConfirmAction(value).then((confirmResult) => {
  205. msg("充值成功");
  206. });
  207. } else {
  208. msg("圈存初始化指令验证失败, 重新初始化");
  209. }
  210. });
  211. });
  212. });
  213. } else {
  214. let cmdArr = val.command.split(",");
  215. uni.showLoading({
  216. title: "写入中",
  217. });
  218. bluetoothUtil.transCmd(cmdArr, "10", function (res) {
  219. var status = res[1].substring(res[1].length - 4, res[1].length);
  220. console.log("打印状态");
  221. console.log(status);
  222. if (status === "9000") {
  223. console.log("修复指令入参");
  224. let response = res.toString();
  225. var dic = {
  226. command: val.command,
  227. cosResponse: response,
  228. rechargeId: val.rechargeId,
  229. };
  230. quanFixAction(dic).then((value) => {
  231. console.log(value);
  232. console.log("修复结果返回");
  233. var fixStatus = value.fixStatus;
  234. //圈存修复COS指令Response信息不足,重新进行修复初始化
  235. if (fixStatus === 3) {
  236. let xfcmdArr = value.command.split(",");
  237. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  238. var status = resValueData[1].substring(
  239. resValueData[1].length - 4,
  240. resValueData[1].length
  241. );
  242. console.log("打印状态");
  243. console.log(status);
  244. if (status === "9000") {
  245. console.log(resValueData);
  246. var valueResponse = resValueData.toString();
  247. console.log(response);
  248. var applyDic = {
  249. command: value.command,
  250. cosResponse: valueResponse,
  251. rechargeId: value.rechargeId,
  252. };
  253. console.log("消费成功");
  254. quanApplyAction(applyDic).then((applyValue) => {
  255. uanConfirmAction(applyValue).then((confirmResult) => {
  256. msg("充值成功");
  257. });
  258. });
  259. }
  260. });
  261. } else if (fixStatus === 2) {
  262. uanConfirmSucessAction(value).then((confirmResult) => {
  263. msg("充值成功");
  264. });
  265. } else if (fixStatus === 1) {
  266. }
  267. });
  268. uni.hideLoading();
  269. }
  270. });
  271. }
  272. };
  273. /*透传*/
  274. const transCmd = (cmd) => {
  275. bluetoothUtil.transCmd(cmd, "10", function (res) {
  276. var status = res[1].substring(res[1].length - 4, res[1].length);
  277. if (status === "9000") {
  278. return res.toString();
  279. }
  280. });
  281. };
  282. /*圈层检测 -假数据校验*/
  283. const quanCheckAction = () => {
  284. var data = {
  285. cardId: state.cardId, //卡号
  286. fee: state.fee,
  287. preBalance: state.mockpreBalance, //假余额
  288. tradeType: 14,
  289. };
  290. const options = {
  291. type: 2,
  292. data: data,
  293. method: "POST",
  294. showLoading: true,
  295. };
  296. return new Promise(async (resolve, reject) => {
  297. const res = await request(quanCheck, options);
  298. const data = stringToJson(res.bizContent);
  299. resolve(data);
  300. }).catch((error) => {
  301. reject(error);
  302. });
  303. };
  304. const quanCheckActionTrue = () => {
  305. console.log("进行真实圈层检测");
  306. var data = {
  307. cardId: card.cardId,
  308. fee: state.fee,
  309. preBalance: card.money,
  310. tradeType: 14,
  311. };
  312. const options = {
  313. type: 2,
  314. data: data,
  315. method: "POST",
  316. showLoading: true,
  317. };
  318. return new Promise(async (resolve, reject) => {
  319. const res = await request(quanCheck, options);
  320. const data = stringToJson(res.bizContent);
  321. resolve(data);
  322. }).catch((error) => {
  323. reject(error);
  324. });
  325. };
  326. /*充值消费*/
  327. const cardCzXFCheckAction = () => {
  328. var data = {
  329. cardId: card.cardId, //修复初始化的指令
  330. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  331. orderNum: state.orderNum, //充值流水号
  332. };
  333. const options = {
  334. type: 2,
  335. data: data,
  336. method: "POST",
  337. showLoading: true,
  338. };
  339. return new Promise(async (resolve, reject) => {
  340. const res = await request(cardCzXFCheck, options);
  341. const data = stringToJson(res.bizContent);
  342. resolve(data);
  343. }).catch((error) => {
  344. reject(error);
  345. });
  346. };
  347. /*圈存修复*/
  348. const quanFixAction = (val) => {
  349. var data = {
  350. command: val.command, //修复初始化的指令
  351. cosResponse: val.cosResponse, //修复初始化结果
  352. rechargeId: val.rechargeId, //充值流水号
  353. };
  354. const options = {
  355. type: 2,
  356. data: data,
  357. method: "POST",
  358. showLoading: true,
  359. };
  360. return new Promise(async (resolve, reject) => {
  361. const res = await request(quanXf, options);
  362. const data = stringToJson(res.bizContent);
  363. resolve(data);
  364. }).catch((error) => {
  365. reject(error);
  366. });
  367. };
  368. /*圈层申请*/
  369. const quanApplyAction = (data) => {
  370. var form = {
  371. cardId: card.cardId,
  372. fee: state.fee,
  373. preBalance: card.money,
  374. tradeType: 14,
  375. command: data.command,
  376. cosResponse: data.cosResponse,
  377. orderId: state.orderNum,
  378. rechargeId: data.rechargeId,
  379. };
  380. const options = {
  381. type: 2,
  382. data: form,
  383. method: "POST",
  384. showLoading: true,
  385. };
  386. return new Promise(async (resolve, reject) => {
  387. const res = await request(quanApply, options);
  388. const data = stringToJson(res.bizContent);
  389. resolve(data);
  390. }).catch((error) => {
  391. reject(error);
  392. });
  393. };
  394. /*圈层确认*/
  395. const uanConfirmAction = (data) => {
  396. console.log("圈层确认进入");
  397. let cmdArr = data.command.split(",");
  398. console.log(cmdArr);
  399. bluetoothUtil.transCmd(cmdArr, "10", function (res) {
  400. console.log("圈层透传");
  401. console.log(res);
  402. var arraylenth = res.length;
  403. var status = res[arraylenth - 1].substring(
  404. res[arraylenth - 1].length - 4,
  405. res[arraylenth - 1].length
  406. );
  407. console.log("打印圈层确认指令状态");
  408. console.log(status);
  409. if (status === "9000") {
  410. var form = {
  411. command: data.command,
  412. cosResponse: res.toString(),
  413. rechargeId: data.rechargeId,
  414. paidAmount: state.fee,
  415. giftAmount: 0,
  416. };
  417. const options = {
  418. type: 2,
  419. data: form,
  420. method: "POST",
  421. showLoading: true,
  422. };
  423. return new Promise(async (resolve, reject) => {
  424. const res = await request(quanConfirm, options);
  425. const data = stringToJson(res.bizContent);
  426. resolve(data);
  427. }).catch((error) => {
  428. reject(error);
  429. });
  430. }
  431. });
  432. };
  433. const uanConfirmSucessAction = (data) => {
  434. var form = {
  435. command: data.command,
  436. cosResponse: "9000",
  437. rechargeId: data.rechargeId,
  438. paidAmount: state.fee,
  439. giftAmount: 0,
  440. };
  441. const options = {
  442. type: 2,
  443. data: form,
  444. method: "POST",
  445. showLoading: true,
  446. };
  447. return new Promise(async (resolve, reject) => {
  448. const res = await request(quanConfirm, options);
  449. const data = stringToJson(res.bizContent);
  450. resolve(data);
  451. }).catch((error) => {
  452. reject(error);
  453. });
  454. };
  455. /*充值检测*/
  456. const czCheckAction = () => {
  457. var form = {
  458. cardId: state.cardId,
  459. openId: getItem(StorageKeys.OpenId),
  460. };
  461. const options = {
  462. type: 2,
  463. data: form,
  464. method: "POST",
  465. showLoading: true,
  466. };
  467. return new Promise(async (resolve, reject) => {
  468. const res = await request(cardCzPayResultCheck, options);
  469. const data = stringToJson(res.bizContent);
  470. resolve(data);
  471. }).catch((error) => {
  472. reject(error);
  473. });
  474. };
  475. /*充值申请*/
  476. const cardCzApplyAction = () => {
  477. var data = {
  478. cardId: state.cardId,
  479. openId: getItem(StorageKeys.OpenId),
  480. rechargeMoney: state.fee,
  481. };
  482. const options = {
  483. type: 2,
  484. data: data,
  485. method: "POST",
  486. showLoading: true,
  487. };
  488. return new Promise(async (resolve, reject) => {
  489. const res = await request(cardCzApply, options);
  490. const data = stringToJson(res.bizContent);
  491. resolve(data);
  492. }).catch((error) => {
  493. reject(error);
  494. });
  495. };
  496. //获取微信小程序openid
  497. const getOpenID = () => {
  498. uni.login({
  499. provider: "weixin",
  500. success: function (e) {
  501. wx.request({
  502. url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  503. success: (res: any) => {
  504. state.openid = res.data.openid;
  505. },
  506. });
  507. },
  508. fail: function () {
  509. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  510. },
  511. });
  512. };
  513. //掉起微信支付
  514. const wxPayment = () => {
  515. // #ifdef MP-WEIXIN
  516. const options = {
  517. type: 2,
  518. data: {
  519. openId: getItem(StorageKeys.OpenId),
  520. wxOpenId: state.openid,
  521. cardId: state.cardId,
  522. orderNum: state.orderNum,
  523. payConfigId: wechatPayConfigId,
  524. body: "储值卡充值",
  525. },
  526. method: "POST",
  527. showLoading: true,
  528. };
  529. request(cardCzPay, options).then((res) => {
  530. const data = stringToJson(res.bizContent);
  531. uni.requestPayment({
  532. provider: "wxpay",
  533. orderInfo: "",
  534. timeStamp: data.timestamp,
  535. nonceStr: data.noncestr,
  536. package: data.wxPackage ?? "",
  537. signType: data.signType,
  538. paySign: data.sign,
  539. success: function () {
  540. //回调订单状态
  541. console.log("回调订单状态");
  542. checkOrder();
  543. },
  544. fail: function (err) {
  545. confirm(err, () => {}, "支付失败", false);
  546. },
  547. });
  548. });
  549. // #endif
  550. };
  551. //支付成功改变订单状态
  552. const checkOrder = () => {
  553. const options = {
  554. type: 2,
  555. data: {
  556. cardId: state.cardId,
  557. openId: getItem(StorageKeys.OpenId),
  558. orderNum: state.orderNum,
  559. },
  560. method: "POST",
  561. showLoading: true,
  562. };
  563. request(cardCzPayResult, options).then((res) => {
  564. const data = stringToJson(res.bizContent);
  565. if (data.tradeState === "SUCCESS")
  566. uni.navigateTo({
  567. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}`,
  568. });
  569. console.log(data);
  570. });
  571. };
  572. </script>
  573. <style>
  574. .account {
  575. height: 224rpx;
  576. width: 690rpx;
  577. margin: 30rpx;
  578. position: relative;
  579. }
  580. .account .account-text {
  581. display: flex;
  582. justify-content: space-between;
  583. padding: 20rpx 50rpx;
  584. height: 100%;
  585. }
  586. .account .balance {
  587. display: flex;
  588. flex-direction: column;
  589. justify-content: center;
  590. align-items: flex-start;
  591. color: #ffffff;
  592. }
  593. .account .balance-tit {
  594. font-size: 26rpx;
  595. margin-bottom: 10rpx;
  596. }
  597. .account .balance-val {
  598. font-size: 56rpx;
  599. }
  600. .account .right-box {
  601. display: flex;
  602. flex-direction: column;
  603. justify-content: flex-start;
  604. align-items: flex-end;
  605. }
  606. .account .right-box .no {
  607. font-size: 26rpx;
  608. color: #ffffff;
  609. }
  610. .account .right-box .btn {
  611. font-size: 26rpx;
  612. padding: 0 20rpx;
  613. box-sizing: border-box;
  614. height: 42rpx;
  615. line-height: 42rpx;
  616. color: #28d20f;
  617. background: #ffffff;
  618. border-radius: 21rpx;
  619. display: inline-block;
  620. margin-top: 18rpx;
  621. }
  622. .account .head-bg {
  623. width: 690rpx;
  624. height: 224rpx;
  625. position: absolute;
  626. left: 0;
  627. top: 0;
  628. z-index: -99;
  629. }
  630. .input-box {
  631. display: flex;
  632. flex-direction: column;
  633. justify-content: center;
  634. align-items: center;
  635. padding: 20rpx 0;
  636. }
  637. .input-box .input {
  638. width: 430rpx;
  639. height: 98rpx;
  640. line-height: 98rpx;
  641. background: #f8f8f8;
  642. border: 1px solid #999999;
  643. border-radius: 6rpx;
  644. font-size: 30rpx;
  645. text-align: center;
  646. }
  647. .input-box .tips {
  648. color: #666666;
  649. font-size: 26rpx;
  650. margin-top: 18rpx;
  651. }
  652. .tabs {
  653. }
  654. .tabs .tab-tit {
  655. font-size: 30rpx;
  656. color: #333;
  657. padding: 45rpx 0 22rpx 30rpx;
  658. }
  659. .tabs .tab {
  660. display: flex;
  661. flex-wrap: wrap;
  662. justify-content: space-evenly;
  663. }
  664. .tabs .tab .item {
  665. width: 210rpx;
  666. height: 100rpx;
  667. background: #f6fff7;
  668. border: 1px solid #dcdde1;
  669. box-sizing: border-box;
  670. line-height: 100rpx;
  671. border-radius: 6rpx;
  672. text-align: center;
  673. margin-bottom: 24rpx;
  674. color: #333333;
  675. font-size: 32rpx;
  676. }
  677. .tabs .tab .item.active {
  678. border: 1px solid #24cc49;
  679. color: #24cc49;
  680. }
  681. .btn-primary {
  682. width: 670rpx;
  683. height: 80rpx;
  684. line-height: 80rpx;
  685. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  686. border-radius: 40rpx;
  687. font-size: 32rpx;
  688. color: #ffffff;
  689. margin: 200rpx 40rpx 0;
  690. text-align: center;
  691. }
  692. </style>