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

1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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. const openidData = stringToJson(result.data);
  704. // setItem("QYorder", result.data);
  705. state.openid = openidData.openid
  706. });
  707. // #endif
  708. }
  709. //掉起微信支付
  710. const wxPayment = () => {
  711. // #ifdef MP-WEIXIN
  712. const options = {
  713. type: 2,
  714. data: {
  715. openId: getItem(StorageKeys.OpenId),
  716. wxOpenId: state.openid,
  717. cardId: state.cardId,
  718. orderNum: state.orderNum,
  719. payConfigId: wechatPayConfigId,
  720. body: "储值卡充值",
  721. },
  722. method: "POST",
  723. showLoading: true,
  724. };
  725. request(cardCzPay, options).then((res) => {
  726. const data = stringToJson(res.bizContent);
  727. uni.requestPayment({
  728. provider: "wxpay",
  729. orderInfo: "",
  730. timeStamp: data.timestamp,
  731. nonceStr: data.noncestr,
  732. package: data.wxPackage ? data.wxPackage : "",
  733. signType: data.signType,
  734. paySign: data.sign,
  735. success: function () {
  736. //回调订单状态
  737. console.log("回调订单状态");
  738. checkOrder();
  739. },
  740. fail: function (err) {
  741. confirm(err, () => { }, "支付失败", false);
  742. },
  743. });
  744. });
  745. // #endif
  746. };
  747. //掉起支付宝支付
  748. const aliPayment = () => {
  749. // #ifdef MP-ALIPAY
  750. my.getAuthCode({
  751. scopes: 'auth_base',
  752. success: res => {
  753. const optionsUser = {
  754. type: 2,
  755. data: {
  756. payConfigId: aliPayConfigId,
  757. code: res.authCode
  758. },
  759. method: "POST",
  760. showLoading: true,
  761. };
  762. request(obtainUserId, optionsUser).then((res) => {
  763. const data = stringToJson(res.bizContent);
  764. const optionsali = {
  765. type: 2,
  766. data: {
  767. openId: getItem(StorageKeys.OpenId),
  768. wxOpenId: data.openId,
  769. cardId: state.cardId,
  770. orderNum: state.orderNum,
  771. payConfigId: "6a9a54123456578934edfre132b1234",
  772. body: "储值卡充值",
  773. },
  774. method: "POST",
  775. showLoading: true,
  776. };
  777. request(cardCzPay, optionsali).then((res) => {
  778. const data = stringToJson(res.bizContent);
  779. my.tradePay({
  780. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  781. tradeNO: data.tranPackage,
  782. success: res => {
  783. console.log("支付成功", res);
  784. checkOrder();
  785. },
  786. fail: res => {
  787. confirm(res, () => { }, "支付失败", false);
  788. },
  789. });
  790. });
  791. });
  792. },
  793. fail: err => {
  794. console.log('my.getAuthCode 调用失败', err)
  795. }
  796. });
  797. // #endif
  798. };
  799. //支付成功改变订单状态
  800. const checkOrder = () => {
  801. const options = {
  802. type: 2,
  803. data: {
  804. cardId: state.cardId,
  805. openId: getItem(StorageKeys.OpenId),
  806. orderNum: state.orderNum,
  807. },
  808. method: "POST",
  809. showLoading: true,
  810. };
  811. request(cardCzPayResult, options).then((res) => {
  812. const data = stringToJson(res.bizContent);
  813. if (data.tradeState === "SUCCESS") {
  814. if (state.transWay == 'blu') {
  815. uni.redirectTo({
  816. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  817. });
  818. } else {
  819. uni.redirectTo({
  820. url: `/pages/nfc/nfc?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  821. });
  822. }
  823. }
  824. // state.isShowBlue=true;
  825. console.log(data);
  826. });
  827. };
  828. const goRecord = () => {
  829. uni.navigateTo({
  830. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  831. })
  832. }
  833. </script>
  834. <style>
  835. .account {
  836. height: 224rpx;
  837. width: 690rpx;
  838. margin: 30rpx;
  839. position: relative;
  840. }
  841. .account .account-text {
  842. display: flex;
  843. justify-content: space-between;
  844. padding: 20rpx 50rpx;
  845. height: 100%;
  846. }
  847. .account .balance {
  848. display: flex;
  849. flex-direction: column;
  850. justify-content: center;
  851. align-items: flex-start;
  852. color: #ffffff;
  853. }
  854. .account .balance-tit {
  855. font-size: 26rpx;
  856. margin-bottom: 10rpx;
  857. }
  858. .account .balance-val {
  859. font-size: 56rpx;
  860. }
  861. .account .right-box {
  862. display: flex;
  863. flex-direction: column;
  864. justify-content: flex-start;
  865. align-items: flex-end;
  866. }
  867. .account .right-box .no {
  868. font-size: 26rpx;
  869. color: #ffffff;
  870. }
  871. .account .right-box .btn {
  872. font-size: 26rpx;
  873. padding: 0 20rpx;
  874. box-sizing: border-box;
  875. height: 42rpx;
  876. line-height: 42rpx;
  877. color: #28d20f;
  878. background: #ffffff;
  879. border-radius: 21rpx;
  880. display: inline-block;
  881. margin-top: 18rpx;
  882. }
  883. .account .head-bg {
  884. width: 690rpx;
  885. height: 224rpx;
  886. position: absolute;
  887. left: 0;
  888. top: 0;
  889. z-index: -99;
  890. }
  891. .input-box {
  892. display: flex;
  893. flex-direction: column;
  894. justify-content: center;
  895. align-items: center;
  896. padding: 20rpx 0;
  897. }
  898. .input-box .input {
  899. width: 430rpx;
  900. height: 98rpx;
  901. line-height: 98rpx;
  902. background: #f8f8f8;
  903. border: 1px solid #999999;
  904. border-radius: 6rpx;
  905. font-size: 30rpx;
  906. text-align: center;
  907. }
  908. .input-box .tips {
  909. color: #666666;
  910. font-size: 26rpx;
  911. margin-top: 18rpx;
  912. }
  913. .tabs {}
  914. .tabs .tab-tit {
  915. font-size: 30rpx;
  916. color: #333;
  917. padding: 45rpx 0 22rpx 30rpx;
  918. }
  919. .tabs .tab {
  920. display: flex;
  921. flex-wrap: wrap;
  922. justify-content: space-evenly;
  923. }
  924. .tabs .tab .item {
  925. width: 210rpx;
  926. height: 100rpx;
  927. background: #f6fff7;
  928. border: 1px solid #dcdde1;
  929. box-sizing: border-box;
  930. line-height: 100rpx;
  931. border-radius: 6rpx;
  932. text-align: center;
  933. margin-bottom: 24rpx;
  934. color: #333333;
  935. font-size: 32rpx;
  936. }
  937. .tabs .tab .item.active {
  938. border: 1px solid #24cc49;
  939. color: #24cc49;
  940. }
  941. .btn-primary {
  942. width: 670rpx;
  943. height: 80rpx;
  944. line-height: 80rpx;
  945. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  946. border-radius: 40rpx;
  947. font-size: 32rpx;
  948. color: #ffffff;
  949. margin: 200rpx 40rpx 0;
  950. text-align: center;
  951. }
  952. .uni-list {
  953. padding: 120rpx 10rpx 0 10rpx;
  954. font-size: 34rpx;
  955. }
  956. label {
  957. display: flex;
  958. justify-content: space-between;
  959. margin-top: 30rpx;
  960. }
  961. </style>