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 26KB

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