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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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. 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 datas = require("../../static/etcUtil/datas.js");
  84. const bluetoothUtil = require("../../static/etcUtil/index.js");
  85. const cmd = require("../../static/etcUtil/cmdConfig.js");
  86. const tools = require("../../static/etcUtil/tools.js");
  87. const NFCAPI = require('../../static/nfc/NFCAPI.js');
  88. const state = reactive({
  89. transWayTypeShow: false,
  90. transWayTypeList: [{
  91. label: "蓝牙",
  92. value: "blu",
  93. }, {
  94. label: "NFC",
  95. value: "nfc",
  96. }
  97. ],
  98. isShowBlue: false,
  99. moneryArray: [{
  100. name: '50元',
  101. value: 50
  102. }, {
  103. name: '100元',
  104. value: 100
  105. }, {
  106. name: '200元',
  107. value: 200
  108. }, {
  109. name: '300元',
  110. value: 300
  111. }, {
  112. name: '500元',
  113. value: 500
  114. }, {
  115. name: '1000元',
  116. value: 1000
  117. }],
  118. tableIndex: 0,
  119. openid: "",
  120. connectSuccess: undefined,
  121. fee: 5000,
  122. money: 50,
  123. orderNum: "",
  124. transWayName: "蓝牙",
  125. transWay: "blu", //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  126. cardId: "", //卡号 需要传参
  127. mockpreBalance: 2000, //fix:模拟余额 目前没有检测状态接口,第一次会模拟圈层检测来检测状态
  128. show: false,
  129. items: [{
  130. value: '0',
  131. name: '微信',
  132. checked: 'true'
  133. },
  134. {
  135. value: '1',
  136. name: '对公账户'
  137. }
  138. ],
  139. current: 0
  140. });
  141. const selectConfirm = (item : any) => {
  142. // item.map((val, index) => {
  143. // state.form.useUserType = val.value;
  144. // state.form.useUserTypeName = val.label;
  145. // });
  146. state.transWayName = item[0].label
  147. state.transWay = item[0].value
  148. };
  149. //读卡信息
  150. const card : any = reactive({
  151. cardId: "",
  152. netId: "",
  153. cardType: "",
  154. startTime: "",
  155. endTime: "",
  156. userName: "",
  157. idNum: "",
  158. vehiclePlate: "",
  159. vehiclePlateColor: "",
  160. color: "",
  161. version: "",
  162. type: "",
  163. favourable: "",
  164. money: undefined,
  165. v_userType: "",
  166. });
  167. onLoad((option) => {
  168. /*获取openId 用途:(用户支付)*/
  169. // #ifdef MP-WEIXIN
  170. getOpenID();/*传参*/
  171. // #endif
  172. console.log("开始option", option)
  173. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  174. state.cardId = option.cardId;
  175. state.connectSuccess = option.connectSuccess;
  176. state.orderNum = getItem("orderNum");
  177. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  178. if (option.fee) {
  179. state.fee = option.fee
  180. state.money = option.fee / 100
  181. } else {
  182. state.fee = state.money * 100; //元换成分
  183. }
  184. console.log("state.fee", option, state.fee)
  185. //跳转过来走圈存流程
  186. if (state.connectSuccess === "1") {
  187. /*读卡*/
  188. getCardId();
  189. } else {
  190. quanCheckActionTrue().then((val : any) => {
  191. console.log("圈层检测val", val)
  192. //如果 圈层检测正常
  193. if (val.chargeStatus === 1) {
  194. console.log(`进行充值检测`);
  195. czCheckAction().then((checkResult : any) => {
  196. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  197. if (checkResult.orders && checkResult.orders.length > 0) {
  198. //拿到订单,存起来
  199. state.orderNum = checkResult.orders[0].orderNum;
  200. setItem("orderNum", state.orderNum);
  201. // 检测用户是否存在有半条流水
  202. // go()
  203. } else {
  204. console.log('没有可修复的流水')
  205. }
  206. });
  207. } else {
  208. // 检测用户是否存在有半条流水
  209. // go()
  210. }
  211. });
  212. }
  213. });
  214. function radioChange(evt) {
  215. console.log('输出内容', evt)
  216. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  217. }
  218. function go(money) {
  219. let content = ""
  220. if (money) {
  221. content = '待消费订单' + money + '元'
  222. } else {
  223. content = '待消费订单'
  224. }
  225. uni.showModal({
  226. title: '提示',
  227. content: 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. quanCheckActionTrue().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(state.money)
  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, card.money);
  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. },
  696. fail: function () {
  697. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  698. },
  699. });
  700. };
  701. const getOpenid = (code) => {
  702. const options = {
  703. type: 2,
  704. data: {
  705. "jsCode": code
  706. },
  707. method: "POST",
  708. showLoading: true,
  709. };
  710. // #ifdef MP-WEIXIN
  711. request(getOpenidApi, options).then((res) => {
  712. const result = stringToJson(res.bizContent);
  713. console.log("获取微信小程序openid", result);
  714. const openidData = stringToJson(result.data);
  715. // setItem("QYorder", result.data);
  716. state.openid = openidData.openid
  717. });
  718. // #endif
  719. }
  720. //掉起微信支付
  721. const wxPayment = () => {
  722. // #ifdef MP-WEIXIN
  723. const options = {
  724. type: 2,
  725. data: {
  726. openId: getItem(StorageKeys.OpenId),
  727. wxOpenId: state.openid,
  728. cardId: state.cardId,
  729. orderNum: state.orderNum,
  730. payConfigId: wechatPayConfigId,
  731. body: "储值卡充值",
  732. },
  733. method: "POST",
  734. showLoading: true,
  735. };
  736. request(cardCzPay, options).then((res) => {
  737. const data = stringToJson(res.bizContent);
  738. uni.requestPayment({
  739. provider: "wxpay",
  740. orderInfo: "",
  741. timeStamp: data.timestamp,
  742. nonceStr: data.noncestr,
  743. package: data.wxPackage ? data.wxPackage : "",
  744. signType: data.signType,
  745. paySign: data.sign,
  746. success: function () {
  747. //回调订单状态
  748. console.log("回调订单状态");
  749. checkOrder();
  750. },
  751. fail: function (err) {
  752. confirm(err, () => { }, "支付失败", false);
  753. },
  754. });
  755. });
  756. // #endif
  757. };
  758. //掉起支付宝支付
  759. const aliPayment = () => {
  760. // #ifdef MP-ALIPAY
  761. my.getAuthCode({
  762. scopes: 'auth_base',
  763. success: res => {
  764. const optionsUser = {
  765. type: 2,
  766. data: {
  767. payConfigId: aliPayConfigId,
  768. code: res.authCode
  769. },
  770. method: "POST",
  771. showLoading: true,
  772. };
  773. request(obtainUserId, optionsUser).then((res) => {
  774. const data = stringToJson(res.bizContent);
  775. const optionsali = {
  776. type: 2,
  777. data: {
  778. openId: getItem(StorageKeys.OpenId),
  779. wxOpenId: data.openId,
  780. cardId: state.cardId,
  781. orderNum: state.orderNum,
  782. payConfigId: "6a9a54123456578934edfre132b1234",
  783. body: "储值卡充值",
  784. },
  785. method: "POST",
  786. showLoading: true,
  787. };
  788. request(cardCzPay, optionsali).then((res) => {
  789. const data = stringToJson(res.bizContent);
  790. my.tradePay({
  791. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  792. tradeNO: data.tranPackage,
  793. success: res => {
  794. console.log("支付成功", res);
  795. checkOrder();
  796. },
  797. fail: res => {
  798. confirm(res, () => { }, "支付失败", false);
  799. },
  800. });
  801. });
  802. });
  803. },
  804. fail: err => {
  805. console.log('my.getAuthCode 调用失败', err)
  806. }
  807. });
  808. // #endif
  809. };
  810. //支付成功改变订单状态
  811. const checkOrder = () => {
  812. const options = {
  813. type: 2,
  814. data: {
  815. cardId: state.cardId,
  816. openId: getItem(StorageKeys.OpenId),
  817. orderNum: state.orderNum,
  818. },
  819. method: "POST",
  820. showLoading: true,
  821. };
  822. request(cardCzPayResult, options).then((res) => {
  823. const data = stringToJson(res.bizContent);
  824. if (data.tradeState === "SUCCESS") {
  825. if (state.transWay == 'blu') {
  826. uni.redirectTo({
  827. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  828. });
  829. } else {
  830. uni.redirectTo({
  831. url: `/pages/nfc/nfc?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  832. });
  833. }
  834. }
  835. console.log(data);
  836. });
  837. };
  838. const goRecord = () => {
  839. uni.navigateTo({
  840. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  841. })
  842. }
  843. </script>
  844. <style>
  845. .account {
  846. height: 224rpx;
  847. width: 690rpx;
  848. margin: 30rpx;
  849. position: relative;
  850. }
  851. .account .account-text {
  852. display: flex;
  853. justify-content: space-between;
  854. padding: 20rpx 50rpx;
  855. height: 100%;
  856. }
  857. .account .balance {
  858. display: flex;
  859. flex-direction: column;
  860. justify-content: center;
  861. align-items: flex-start;
  862. color: #ffffff;
  863. }
  864. .account .balance-tit {
  865. font-size: 26rpx;
  866. margin-bottom: 10rpx;
  867. }
  868. .account .balance-val {
  869. font-size: 56rpx;
  870. }
  871. .account .right-box {
  872. display: flex;
  873. flex-direction: column;
  874. justify-content: flex-start;
  875. align-items: flex-end;
  876. }
  877. .account .right-box .no {
  878. font-size: 26rpx;
  879. color: #ffffff;
  880. }
  881. .account .right-box .btn {
  882. font-size: 26rpx;
  883. padding: 0 20rpx;
  884. box-sizing: border-box;
  885. height: 42rpx;
  886. line-height: 42rpx;
  887. color: #28d20f;
  888. background: #ffffff;
  889. border-radius: 21rpx;
  890. display: inline-block;
  891. margin-top: 18rpx;
  892. }
  893. .account .head-bg {
  894. width: 690rpx;
  895. height: 224rpx;
  896. position: absolute;
  897. left: 0;
  898. top: 0;
  899. z-index: -99;
  900. }
  901. .input-box {
  902. display: flex;
  903. flex-direction: column;
  904. justify-content: center;
  905. align-items: center;
  906. padding: 20rpx 0;
  907. }
  908. .input-box .input {
  909. width: 430rpx;
  910. height: 98rpx;
  911. line-height: 98rpx;
  912. background: #f8f8f8;
  913. border: 1px solid #999999;
  914. border-radius: 6rpx;
  915. font-size: 30rpx;
  916. text-align: center;
  917. }
  918. .input-box .tips {
  919. color: #666666;
  920. font-size: 26rpx;
  921. margin-top: 18rpx;
  922. }
  923. .tabs {}
  924. .tabs .tab-tit {
  925. font-size: 30rpx;
  926. color: #333;
  927. padding: 45rpx 0 22rpx 30rpx;
  928. }
  929. .tabs .tab {
  930. display: flex;
  931. flex-wrap: wrap;
  932. justify-content: space-evenly;
  933. }
  934. .tabs .tab .item {
  935. width: 210rpx;
  936. height: 100rpx;
  937. background: #f6fff7;
  938. border: 1px solid #dcdde1;
  939. box-sizing: border-box;
  940. line-height: 100rpx;
  941. border-radius: 6rpx;
  942. text-align: center;
  943. margin-bottom: 24rpx;
  944. color: #333333;
  945. font-size: 32rpx;
  946. }
  947. .tabs .tab .item.active {
  948. border: 1px solid #24cc49;
  949. color: #24cc49;
  950. }
  951. .btn-primary {
  952. width: 670rpx;
  953. height: 80rpx;
  954. line-height: 80rpx;
  955. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  956. border-radius: 40rpx;
  957. font-size: 32rpx;
  958. color: #ffffff;
  959. margin: 200rpx 40rpx 0;
  960. text-align: center;
  961. }
  962. .uni-list {
  963. padding: 120rpx 10rpx 0 10rpx;
  964. font-size: 34rpx;
  965. }
  966. label {
  967. display: flex;
  968. justify-content: space-between;
  969. margin-top: 30rpx;
  970. }
  971. </style>