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

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