index.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.13/vue.js"></script>
  8. <script src="https://g.tbcdn.cn/mtb/lib-flexible/0.3.2/??flexible_css.js,flexible.js"></script>
  9. </head>
  10. <style>
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. #container {
  16. overflow: hidden;
  17. width: 100%;
  18. height: 51.1733rem;
  19. margin-bottom: 1.8667rem;
  20. background: url('http://reader-wx.ai160.com/images/reader/v3/bg.jpg') no-repeat;
  21. background-size: 100% 100%;
  22. }
  23. .commoditys {
  24. display: flex;
  25. align-items: center;
  26. justify-content: space-between;
  27. margin: 5.2267rem auto;
  28. width: 9.0133rem;
  29. height: 3.4667rem;
  30. padding: 0.3733rem 0.2667rem;
  31. box-sizing: border-box;
  32. border-radius: 20px;
  33. }
  34. .commodity {
  35. position: relative;
  36. width: 2.5867rem;
  37. height: 2.5867rem;
  38. border-radius: 6px;
  39. padding: 0.0533rem;
  40. background-clip: content-box !important;
  41. border: 2px solid white;
  42. }
  43. .active {
  44. position: absolute;
  45. width: 0.72rem;
  46. height: 0.48rem;
  47. right: 0;
  48. bottom: 0;
  49. }
  50. .aborder {
  51. border-color: #ff935e;
  52. }
  53. .c-1 {
  54. background: url('http://reader-wx.ai160.com/images/reader/v3/299.png') no-repeat;
  55. background-size: contain;
  56. }
  57. .c-2 {
  58. background: url('http://reader-wx.ai160.com/images/reader/v3/99.png') no-repeat;
  59. background-size: contain;
  60. }
  61. .c-3 {
  62. background: url('http://reader-wx.ai160.com/images/reader/v3/15.png') no-repeat;
  63. background-size: contain;
  64. }
  65. .payBox {
  66. position: fixed;
  67. display: flex;
  68. align-items: center;
  69. justify-content: space-between;
  70. box-sizing: border-box;
  71. left: 0;
  72. bottom: 0;
  73. width: 100%;
  74. padding: 0.4rem 0.48rem;
  75. background: white;
  76. }
  77. .payBox .left {
  78. font-size: 0.48rem;
  79. }
  80. .price {
  81. color: #ff9108;
  82. font-size: 0.64rem;
  83. font-weight: bold;
  84. }
  85. .pay {
  86. padding: 0.1867rem 0.6933rem;
  87. background: #ff9108;
  88. color: white;
  89. font-weight: 500;
  90. border-radius: 0.6133rem;
  91. font-size: 0.48rem;
  92. }
  93. .mask {
  94. position: fixed;
  95. display: flex;
  96. align-items: center;
  97. justify-content: center;
  98. width: 100vw;
  99. height: 100vh;
  100. left: 0;
  101. top: 0;
  102. background-color: rgba(0, 0, 0, 0.568);
  103. }
  104. .payTips {
  105. display: flex;
  106. flex-direction: column;
  107. align-items: center;
  108. width: 6.4533rem;
  109. height: 6.96rem;
  110. padding: 1.0133rem;
  111. box-sizing: border-box;
  112. border-radius: 11px;
  113. background: white;
  114. }
  115. .simg {
  116. width: 1.6rem;
  117. height: 1.7867rem;
  118. }
  119. .t1 {
  120. margin: 0.8rem 0;
  121. font-size: 0.48rem;
  122. }
  123. .goXkx {
  124. padding: 0.1rem 1.3333rem;
  125. font-size: 0.4267rem;
  126. color: white;
  127. background: linear-gradient(180deg, #66d751 0%, #65d952 100%);
  128. border-radius: 0.4rem;
  129. }
  130. </style>
  131. <body>
  132. <div id="container">
  133. <div class="commoditys" v-if="products.length>0">
  134. <div v-for="item in products" ::key="item.id" :class="['commodity',item.payType=='LIFELONG'?'c-1':item.payType=='YEAR'?'c-2':'c-3', active==item.id?'aborder':'']" @click="selected(item)">
  135. <img src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active" v-show="active==item.id" />
  136. </div>
  137. </div>
  138. <div class="payBox" v-if="active!=''">
  139. <div class="left">
  140. {{product.title}}
  141. <span class="price">{{product.price/100}}</span>
  142. </div>
  143. <div class="pay" @click="pay">立即支付</div>
  144. </div>
  145. <div class="mask" v-if="mask">
  146. <div class="payTips">
  147. <img src="https://reader-wx.ai160.com/images/reader/v3/right.webp" class="simg" />
  148. <div class="t1">支付成功</div>
  149. <div class="goXkx" @click="closeMask">确认</div>
  150. </div>
  151. </div>
  152. </div>
  153. </body>
  154. <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.min.js"></script>
  155. <script>
  156. let app = new Vue({
  157. el: '#container',
  158. data: {
  159. products: [],
  160. product: {},
  161. active: '',
  162. uid: '',
  163. code: '',
  164. mask: false
  165. },
  166. mounted() {
  167. // 原始URL
  168. var url = location.search
  169. // 创建URLSearchParams对象
  170. var searchParams = new URLSearchParams(url)
  171. // 获取code参数的值
  172. var code = searchParams.get('code')
  173. var first = searchParams.get('first')
  174. var uid = searchParams.get('uid')
  175. if (uid) {
  176. this.uid = uid
  177. }
  178. if (first) {
  179. axios({
  180. method: 'post',
  181. url: 'https://reader-api.ai160.com/wx/userEvent/v2',
  182. headers: {
  183. uid: this.uid,
  184. channelCode: '3001'
  185. },
  186. data: {
  187. action: 'IOS_PAY_ENTER'
  188. }
  189. })
  190. }
  191. if (code) {
  192. this.code = code
  193. axios({
  194. method: 'get',
  195. url: 'https://reader-api.ai160.com/wx/v3/product/learn',
  196. headers: {
  197. uid: this.uid,
  198. // uid: 'd83d947655f6455a96f4197d31afa6d4',
  199. channelCode: '3001'
  200. }
  201. }).then(res => {
  202. this.products = res.data.data.productList
  203. this.active = res.data.data.productList[0].id
  204. this.product = res.data.data.productList[0]
  205. })
  206. } else {
  207. // 首次进来参数不含code,需要前端跳转后获取code
  208. this.getWxCode()
  209. }
  210. },
  211. methods: {
  212. getWxCode() {
  213. setTimeout(() => {
  214. const appId = 'wxf05800eea975a68b'
  215. const redirect_uri = encodeURIComponent('https://h5-pay.ai160.com/reader-ios?uid=' + this.uid)
  216. // const redirect_uri = encodeURIComponent('https://h5-pay.ai160.com/reader-ios?uid=d83d947655f6455a96f4197d31afa6d4')
  217. const url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appId + '&redirect_uri=' + redirect_uri + '&response_type=code&scope=snsapi_base#wechat_redirect'
  218. location.href = url
  219. }, 300)
  220. },
  221. selected(e) {
  222. this.active = e.id
  223. this.product = e
  224. },
  225. pay() {
  226. axios({
  227. method: 'post',
  228. url: 'https://reader-api.ai160.com/order/create',
  229. headers: {
  230. uid: this.uid,
  231. // uid: 'd83d947655f6455a96f4197d31afa6d4',
  232. channelCode: '3001'
  233. },
  234. data: {
  235. productId: this.active
  236. }
  237. }).then(res => {
  238. axios({
  239. method: 'post',
  240. url: 'https://reader-api.ai160.com/wx/pay/efun',
  241. headers: {
  242. uid: this.uid,
  243. channelCode: '3001'
  244. },
  245. data: {
  246. payType: 'WXPAY',
  247. code: this.code,
  248. orderId: res.data.data
  249. }
  250. }).then(res => {
  251. let options = res.data.data
  252. WeixinJSBridge.invoke(
  253. 'getBrandWCPayRequest',
  254. {
  255. appId: options.appId, //公众号ID,由商户传入2
  256. timeStamp: options.timeStamp, //时间戳,自1970年以来的秒数
  257. nonceStr: options.nonceStr, //随机串
  258. package: options.package,
  259. signType: options.signType, //微信签名方式:
  260. paySign: options.sign //微信签名
  261. },
  262. async res => {
  263. if (res.err_msg == 'get_brand_wcpay_request:ok') {
  264. this.mask = true
  265. axios({
  266. method: 'post',
  267. url: 'https://reader-api.ai160.com/wx/userEvent/v2',
  268. headers: {
  269. uid: this.uid,
  270. channelCode: '3001'
  271. },
  272. data: {
  273. action: 'IOS_PAY_SUCCESS',
  274. targetContent: this.product.title
  275. }
  276. })
  277. } else {
  278. this.getWxCode()
  279. }
  280. }
  281. )
  282. })
  283. })
  284. axios({
  285. method: 'post',
  286. url: 'https://reader-api.ai160.com/wx/userEvent/v2',
  287. headers: {
  288. uid: this.uid,
  289. channelCode: '3001'
  290. },
  291. data: {
  292. action: 'IOS_PAY_ACTIVITY'
  293. }
  294. })
  295. },
  296. closeMask() {
  297. this.mask = false
  298. this.getWxCode()
  299. }
  300. }
  301. })
  302. </script>
  303. </html>