recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <view class="content">
  3. <view class="title">
  4. <text class="iconfont icon-qian"></text>
  5. <text>江西南昌交通学院</text>
  6. </view>
  7. <view class="input_amount">
  8. <view class="amount_tip">充值金额(元)</view>
  9. <view class="amount_inp">
  10. <text></text>
  11. <input type="number" maxlength="4" v-model="amount" @input="onInput" @blur="onBlur"
  12. placeholder="请输入大于10,小于100元" placeholder-class="ph_class" />
  13. </view>
  14. <text>最多可输入金额100元</text>
  15. </view>
  16. <view class="amount_select">
  17. <view class="amount_btn">
  18. <text @tap="sel_amount(10)" :class="{selStyle:amount == 10}">充10元</text>
  19. <text @tap="sel_amount(20)" :class="{selStyle:amount == 20}">充20元</text>
  20. <text @tap="sel_amount(50)" :class="{selStyle:amount == 50}">充50元</text>
  21. <text @tap="sel_amount(100)" :class="{selStyle:amount == 100}">充100元</text>
  22. </view>
  23. <view class="reminder">温馨提示:最少充值金额为10元</view>
  24. <view class="payment">支付金额:<text>{{amount}}</text>元</view>
  25. <button class="btn_submit" type="primary" @tap="chongzhi">确认提交</button>
  26. <button class="btn_tel" type="default" @tap="callPhone">客服热线:{{phone_number}}</button>
  27. <view class="tips">
  28. 尊敬的用户,你好!因项目提现业务配置问题导致您无法提现对此,我们深表歉意!您可致电运营商处理提现问题,运营商电话:13645689854。感谢您对我们工作的支持和理解。
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. amount: 10.0.toFixed(0), // 金额
  38. phone_number: '13645689854', // 客户热线电话
  39. userinfo: '', // 用户信息
  40. order_id: '', // 订单号
  41. pay_info: '', // 支付参数。将此参数透传给支付 SDK 发起支付
  42. access_token: '',
  43. sub_appid: '',
  44. card_number: '',
  45. user_name: '',
  46. test: getApp().globalData.test
  47. };
  48. },
  49. onLoad(options) {
  50. try {
  51. // 获取存储的用户数据
  52. const value = uni.getStorageSync('userinfo_storage_key')
  53. let item = decodeURIComponent(options.item)
  54. // console.log(item)
  55. if (item === '{}' && value == '') { // 如果没有用户信息,返回首页
  56. uni.redirectTo({
  57. url: '../index/index'
  58. });
  59. return;
  60. }
  61. // 先用传过来的用户信息
  62. if (item != '') {
  63. // 处理JSON字符串
  64. // this.userinfo = item.replace(/"/g, "'");
  65. this.userinfo = JSON.parse(item)
  66. // 更新存储的用户信息
  67. uni.setStorageSync('userinfo_storage_key', this.userinfo)
  68. } else if (value != '') {
  69. // 处理JSON字符串
  70. // this.userinfo = value.replace(/"/g, "'");
  71. this.userinfo = value;
  72. }
  73. } catch (e) {
  74. console.log(e)
  75. }
  76. this.sub_appid = this.userinfo.sub_appid
  77. this.card_number = this.userinfo.card_number
  78. this.user_name = this.userinfo.name
  79. // 获取应用有效凭证
  80. this.get_valid_credentials()
  81. },
  82. methods: {
  83. /**
  84. * 获取应用有效凭证
  85. */
  86. async get_valid_credentials() {
  87. const res = await this.$myRequest({
  88. host: 'wecard',
  89. url: '/cgi-bin/oauth2/token',
  90. method: 'POST',
  91. header: {
  92. 'content-type': 'application/json'
  93. },
  94. data: {
  95. 'app_key': this.userinfo.appkey,
  96. 'app_secret': this.userinfo.app_secret,
  97. 'grant_type': 'client_credentials',
  98. 'scope': 'base',
  99. 'ocode': this.userinfo.ocode
  100. }
  101. });
  102. if (typeof(res.data.access_token) != 'undefined') {
  103. // 获取到应用有效凭证,保存到页面变量中
  104. this.access_token = res.data.access_token
  105. } else {
  106. uni.showToast({
  107. title: '获取凭证失败',
  108. duration: 2000
  109. })
  110. }
  111. },
  112. /**
  113. * 组合地址,发起支付
  114. */
  115. async jsapi() {
  116. const res = await this.$myRequest({
  117. host: 'wecard',
  118. url: '/cgi-bin/pay/app/mppay',
  119. method: 'POST',
  120. header: {
  121. 'content-type': 'application/json'
  122. },
  123. data: {
  124. 'access_token': this.access_token,
  125. 'sub_appid': this.sub_appid,
  126. 'user_id': this.card_number,
  127. 'order_id': this.order_id = get_order_id('shuifei'),
  128. 'amount': this.amount * 100,
  129. 'order_type': 1,
  130. // 'callback_url': 'http://x3ys5i.natappfree.cc'
  131. 'callback_url': this.$code_base_url + '/HotWater/wxpayrecharge.action'
  132. }
  133. })
  134. this.pay_info = res.data.data.pay_info
  135. // 发起支付
  136. this.pay_amount()
  137. },
  138. // 调起支付
  139. pay_amount() {
  140. var OpenMidas = require("@/static/openMidas.js") // 引入小程序目录下的SDK文件
  141. // 设置支付配置
  142. wx['OpenMidasConfig'] = {
  143. apiCommonConf: {
  144. version: "weixiao"
  145. },
  146. cgiDomain: {
  147. test: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
  148. },
  149. webDomain: "https://midas.weixiao.qq.com/h5", // 私有化参数联系微卡客服进行获取
  150. sandboxWebDomain: "https://midas.weixiao.qq.com/h5" // 私有化参数联系微卡客服进行获取
  151. }
  152. var payInfo = this.pay_info; // 请求mppay接口返回的数据
  153. // var appMetaData = "card_number=" + this.card_number + "&user_name=" + this.user_name + "&account=" + this
  154. // .amount; // 自定义回调数据
  155. OpenMidas.init("test");
  156. OpenMidas.pay(
  157. payInfo,
  158. // function(resultCode, innerCode, resultMsg, appMetaData) {
  159. function(resultCode, innerCode, resultMsg) {
  160. console.log(resultCode); // 支付响应状态码
  161. console.log(innerCode); // 支付响应内部错误码
  162. console.log(resultMsg); // 支付响应说明
  163. console.log(appMetaData); // 自定义回调数据
  164. // todo:处理业务逻辑
  165. uni.showToast({
  166. title: resultMsg,
  167. icon: 'success'
  168. })
  169. }
  170. // },
  171. // appMetaData
  172. )
  173. },
  174. /**
  175. * 输入充值金额
  176. */
  177. onInput(e) {
  178. if (this.test) {
  179. return
  180. }
  181. const v = e.detail.value
  182. this.amount = 10
  183. const zero = /^(0{1,})|[^0-9]/g
  184. let final = 0
  185. if (!v) {
  186. final = 0
  187. } else {
  188. final = v.toString().replace(zero, (v) => {
  189. return 0
  190. })
  191. if (final.split('')[0] * 1 === 0) {
  192. final = final.slice(1) - 0 || 0
  193. }
  194. if (final > 100) {
  195. final = 100
  196. }
  197. }
  198. this.$nextTick(() => {
  199. this.amount = final.toString() || '0'
  200. })
  201. },
  202. /**
  203. * 输入框,失去焦点时
  204. */
  205. onBlur() {
  206. if (this.test) {
  207. return
  208. }
  209. if (this.amount < 10) {
  210. this.amount = 10
  211. }
  212. },
  213. /**
  214. * 选择充值金额
  215. */
  216. sel_amount(m) {
  217. this.amount = m
  218. },
  219. /**
  220. * 调用接口实现充值功能
  221. */
  222. chongzhi() {
  223. if (this.test) {
  224. uni.showModal({
  225. title: '提示',
  226. content: '您选择了充值:¥' + this.amount + ' 元',
  227. cancelText: '算了',
  228. confirmText: '充值',
  229. success: (res) => {
  230. if (res.confirm) {
  231. // 组合地址,发起支付
  232. this.jsapi()
  233. } else if (res.cancel) {
  234. return
  235. }
  236. }
  237. })
  238. return
  239. }
  240. if (this.amount < 10 || this.amount > 100) {
  241. uni.showToast({
  242. icon: 'none',
  243. title: '最少充值10元,最多充值100元!',
  244. mask: true,
  245. duration: 3000
  246. })
  247. return
  248. } else {
  249. uni.showModal({
  250. title: '提示',
  251. content: '您选择了充值:¥' + this.amount + ' 元',
  252. cancelText: '算了',
  253. confirmText: '充值',
  254. success: (res) => {
  255. if (res.confirm) {
  256. // 组合地址,发起支付
  257. this.jsapi()
  258. } else if (res.cancel) {
  259. return
  260. }
  261. }
  262. })
  263. }
  264. },
  265. /**
  266. * 拨打电话
  267. */
  268. callPhone() {
  269. uni.makePhoneCall({
  270. phoneNumber: this.phone_number
  271. });
  272. }
  273. }
  274. }
  275. /**
  276. * 时间生成订单号
  277. */
  278. function get_order_id(head) {
  279. const date = new Date()
  280. let year = date.getFullYear()
  281. let month = date.getMonth() + 1
  282. let day = date.getDate()
  283. let hour = date.getHours()
  284. let minute = date.getMinutes()
  285. let second = date.getSeconds()
  286. let millisecond = date.getMilliseconds()
  287. let len_mill = millisecond.toString().length
  288. month = month > 9 ? month : '0' + month
  289. day = day > 9 ? day : '0' + day
  290. second = second > 9 ? second : '0' + second
  291. if (len_mill == 1) {
  292. millisecond = (Math.floor(Math.random() * 9000) + 10000).toString() + millisecond
  293. } else if (len_mill == 2) {
  294. millisecond = (Math.floor(Math.random() * 900) + 1000).toString() + millisecond
  295. } else if (len_mill == 3) {
  296. millisecond = (Math.floor(Math.random() * 900) + 100).toString() + millisecond
  297. }
  298. return `${head}${year}${month}${day}${hour}${minute}${second}${millisecond}`
  299. }
  300. </script>
  301. <style lang="scss" scoped>
  302. .content {
  303. display: flex;
  304. flex-direction: column;
  305. background-color: #F5F5F5;
  306. width: 750rpx;
  307. // height: 100%;
  308. // align-items: stretch;
  309. .title {
  310. display: flex;
  311. align-items: center;
  312. padding: 40rpx;
  313. text:nth-child(1) {
  314. color: $my-color-primary;
  315. font-size: 50rpx;
  316. }
  317. text:nth-child(2) {
  318. font-size: 32rpx;
  319. margin-left: 15rpx;
  320. font-family: Microsoft YaHei-3970(82674968);
  321. color: #333333;
  322. }
  323. }
  324. .input_amount {
  325. background-color: #FFFFFF;
  326. width: 670rpx;
  327. height: 210rpx;
  328. padding: 40rpx 40rpx 0 40rpx;
  329. border-radius: 40rpx 40rpx 0 0;
  330. .amount_tip {
  331. font-size: 32rpx;
  332. font-family: Microsoft YaHei-3970(82674968);
  333. }
  334. .amount_inp {
  335. display: flex;
  336. flex-direction: row;
  337. border-bottom: 1px solid #cccccc;
  338. margin-top: 20rpx;
  339. margin-bottom: 10rpx;
  340. text {
  341. width: 50rpx;
  342. height: 74rpx;
  343. font-size: 50rpx;
  344. font-weight: bold;
  345. padding-top: 6rpx;
  346. font-family: Microsoft YaHei-3970(82674968);
  347. }
  348. text::before {
  349. content: '¥';
  350. }
  351. input {
  352. width: 620rpx;
  353. height: 80rpx;
  354. font-size: 50rpx;
  355. font-weight: bold;
  356. font-family: Microsoft YaHei-3970(82674968);
  357. }
  358. /deep/.ph_class {
  359. font-size: 28rpx;
  360. font-weight: normal;
  361. }
  362. }
  363. text {
  364. font-size: 26rpx;
  365. font-family: Microsoft YaHei-3970(82674968);
  366. font-weight: 500;
  367. }
  368. }
  369. .amount_select {
  370. padding: 40rpx;
  371. .amount_btn {
  372. display: flex;
  373. justify-content: space-between;
  374. margin: 30rpx 0 20rpx;
  375. text {
  376. width: 150rpx;
  377. height: 120rpx;
  378. line-height: 120rpx;
  379. font-size: 32rpx;
  380. font-family: Microsoft YaHei-3970(82674968);
  381. color: #333333;
  382. text-align: center;
  383. background: #FFFFFF;
  384. border: 3rpx solid #AAAAAA;
  385. }
  386. .selStyle {
  387. border: 0rpx;
  388. width: 156rpx;
  389. height: 126rpx;
  390. background: url(../../static/images/jinebeijing2x.png) 0rpx 0rpx no-repeat;
  391. background-size: 100%;
  392. }
  393. }
  394. .reminder {
  395. height: 26rpx;
  396. font-size: 26rpx;
  397. font-family: Microsoft YaHei-3970(82674968);
  398. color: $my-color-primary;
  399. }
  400. .payment {
  401. margin-top: 65rpx;
  402. font-size: 32rpx;
  403. font-family: Microsoft YaHei-3970(82674968);
  404. color: #333333;
  405. text {
  406. color: $my-color-primary;
  407. }
  408. }
  409. button {
  410. margin-top: 38rpx;
  411. }
  412. .btn_submit {
  413. border-radius: 10rpx;
  414. background-color: $my-color-primary;
  415. font-family: Microsoft YaHei-3970(82674968);
  416. color: #FFFFFF;
  417. }
  418. .btn_tel {
  419. border-radius: 10rpx;
  420. background: #CCCCCC;
  421. font-family: Microsoft YaHei-3970(82674968);
  422. color: #FFFFFF;
  423. }
  424. .tips {
  425. margin-top: 20rpx;
  426. font-size: 24rpx;
  427. font-family: Microsoft YaHei-3970(82674968);
  428. color: $my-color-primary;
  429. line-height: 36rpx;
  430. }
  431. }
  432. }
  433. </style>