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

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