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

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