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

recharge.vue 26KB

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