index.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>朗读小咖秀</title>
  7. </head>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. #container {
  14. overflow: hidden;
  15. width: 100%;
  16. height: 51.1733rem;
  17. margin-bottom: 1.8667rem;
  18. background: url('http://reader-wx.ai160.com/images/reader/v3/bg.jpg') no-repeat;
  19. background-size: 100% 100%;
  20. }
  21. .commoditys {
  22. display: flex;
  23. align-items: center;
  24. justify-content: space-between;
  25. margin: 5.2267rem auto;
  26. width: 9.0133rem;
  27. height: 3.4667rem;
  28. padding: 14px 10px;
  29. box-sizing: border-box;
  30. border-radius: 20px;
  31. }
  32. .commodity {
  33. position: relative;
  34. width: 97px;
  35. height: 97px;
  36. border-radius: 6px;
  37. border: 2px solid white;
  38. }
  39. .active {
  40. position: absolute;
  41. width: 27px;
  42. height: 18px;
  43. right: 0;
  44. bottom: 0;
  45. }
  46. .aborder {
  47. border-color: #ff935e;
  48. }
  49. .c-1 {
  50. background: url('http://reader-wx.ai160.com/images/reader/v3/299.png');
  51. background-size: contain;
  52. }
  53. .c-2 {
  54. background: url('http://reader-wx.ai160.com/images/reader/v3/99.png');
  55. background-size: contain;
  56. }
  57. .c-3 {
  58. background: url('http://reader-wx.ai160.com/images/reader/v3/15.png');
  59. background-size: contain;
  60. }
  61. .payBox {
  62. position: fixed;
  63. display: flex;
  64. align-items: center;
  65. justify-content: space-between;
  66. box-sizing: border-box;
  67. left: 0;
  68. bottom: 0;
  69. width: 100%;
  70. padding: 15px 18px;
  71. background: white;
  72. }
  73. .payBox .left {
  74. font-size: 0.48rem;
  75. }
  76. .price {
  77. color: #ff9108;
  78. font-size: 0.64rem;
  79. font-weight: bold;
  80. }
  81. .pay {
  82. padding: 0.1867rem 0.6933rem;
  83. background: #ff9108;
  84. color: white;
  85. font-weight: 500;
  86. border-radius: 0.6133rem;
  87. font-size: 0.48rem;
  88. }
  89. </style>
  90. <body>
  91. <div id="container">
  92. <div class="commoditys" v-if="products.length>0">
  93. <div :class="['commodity c-1', active==products[0].id?'aborder':'']" @click="selected(products[0])">
  94. <img src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active" v-show="active==products[0].id" />
  95. </div>
  96. <div :class="['commodity c-2', active==products[2].id?'aborder':'']" @click="selected(products[2])">
  97. <img src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active" v-show="active==products[2].id" />
  98. </div>
  99. <div :class="['commodity c-3', active==products[1].id?'aborder':'']" @click="selected(products[1])">
  100. <img src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active" v-show="active==products[1].id" />
  101. </div>
  102. </div>
  103. <div class="payBox" v-if="active!=''">
  104. <div class="left">
  105. {{product.title}}
  106. <span class="price">{{product.price/100}}</span>
  107. </div>
  108. <div class="pay" @click="pay">立即支付</div>
  109. </div>
  110. </div>
  111. </body>
  112. <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.13/vue.js"></script>
  113. <script src="https://g.tbcdn.cn/mtb/lib-flexible/0.3.2/??flexible_css.js,flexible.js"></script>
  114. <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.min.js"></script>
  115. <script>
  116. let app = new Vue({
  117. el: '#container',
  118. data: {
  119. products: [],
  120. product: {},
  121. active: '',
  122. uid: '',
  123. code: ''
  124. },
  125. mounted() {
  126. // 原始URL
  127. var url = location.search
  128. // 创建URLSearchParams对象
  129. console.log(url, 'zzzzzzzzzzzzzzzzz')
  130. var searchParams = new URLSearchParams(url)
  131. // 获取code参数的值
  132. var code = searchParams.get('code')
  133. var uid = searchParams.get('uid')
  134. console.log(uid, '=======', code)
  135. if (code) {
  136. this.uid = uid
  137. this.code = code
  138. axios({
  139. method: 'get',
  140. url: 'https://reader-api.efunbox.cn/wx/v3/product/learn',
  141. headers: {
  142. uid: 'd83d947655f6455a96f4197d31afa6d4',
  143. channelCode: '3001'
  144. }
  145. }).then(res => {
  146. this.products = res.data.data.productList
  147. this.active = res.data.data.productList[0].id
  148. this.product = res.data.data.productList[0]
  149. })
  150. } else {
  151. this.getWxCode()
  152. }
  153. },
  154. methods: {
  155. selected(e) {
  156. this.active = e.id
  157. this.product = e
  158. },
  159. pay() {
  160. axios({
  161. method: 'post',
  162. url: 'https://reader-api.efunbox.cn/order/create',
  163. headers: {
  164. uid: 'd83d947655f6455a96f4197d31afa6d4',
  165. channelCode: '3001'
  166. },
  167. data: {
  168. productId: this.active
  169. }
  170. }).then(res => {
  171. console.log(res)
  172. axios({
  173. method: 'post',
  174. url: 'https://reader-api.efunbox.cn/wx/pay/efun',
  175. headers: {
  176. uid: this.uid,
  177. channelCode: '3001'
  178. },
  179. data: {
  180. payType: 'WXPAY',
  181. code: this.code,
  182. orderId: res.data.data
  183. }
  184. }).then(res => {
  185. let options = res.data.data
  186. console.log(options, 'rrrses')
  187. WeixinJSBridge.invoke(
  188. 'getBrandWCPayRequest',
  189. {
  190. appId: options.appId, //公众号ID,由商户传入2
  191. timeStamp: options.timeStamp, //时间戳,自1970年以来的秒数
  192. nonceStr: options.nonceStr, //随机串
  193. package: options.package,
  194. signType: options.signType, //微信签名方式:
  195. paySign: options.sign //微信签名
  196. },
  197. async res => {
  198. if (res.err_msg == 'get_brand_wcpay_request:ok') {
  199. console.log('支付成功')
  200. } else {
  201. this.getWxCode()
  202. }
  203. }
  204. )
  205. })
  206. })
  207. },
  208. getWxCode() {
  209. const appId = 'wxf05800eea975a68b'
  210. const redirect_uri = encodeURIComponent('https://h5-pay.ai160.com/reader-ios?uid=d83d947655f6455a96f4197d31afa6d4')
  211. const url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appId + '&redirect_uri=' + redirect_uri + '&response_type=code&scope=snsapi_base#wechat_redirect'
  212. location.href = url
  213. }
  214. }
  215. })
  216. </script>
  217. </html>