index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
  7. <title>向商家付款</title>
  8. <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
  9. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  10. <script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>
  11. <script type="text/javascript">
  12. function adapter() {
  13. const dpWidth = document.documentElement.clientWidth
  14. const rootFonstSize = (dpWidth * 100) / 750
  15. if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  16. document.documentElement.style.fontSize = rootFonstSize + 'px'
  17. } else {
  18. document.documentElement.style.fontSize = dpWidth
  19. }
  20. }
  21. adapter()
  22. window.onresize = adapter
  23. </script>
  24. <style>
  25. body {
  26. background: #F8F8F8;
  27. }
  28. * {
  29. margin: 0;
  30. padding: 0;
  31. }
  32. #pay {
  33. width: 100%;
  34. height: 100%;
  35. display: flex;
  36. flex-direction: column;
  37. align-items: center;
  38. }
  39. /* .pay_header {
  40. width: 100%;
  41. height: 1.76rem;
  42. display: flex;
  43. justify-content: center;
  44. align-items: center;
  45. background: #FFFFFF;
  46. }
  47. .pay-header-nei {
  48. width: 6.86rem;
  49. height: 100%;
  50. display: flex;
  51. }
  52. .pay-header-nei-in {
  53. margin-top: 1.07rem;
  54. font-size: 0.36rem;
  55. font-weight: 500;
  56. color: #333333;
  57. text-align: center;
  58. margin-left: 2.17rem;
  59. }
  60. .pay-header-nei-left {
  61. width: 0.36rem;
  62. height: 0.36rem;
  63. margin-top: 1.17rem;
  64. }
  65. .pay-header-nei-left img {
  66. width: 100%;
  67. height: 100%;
  68. display: block;
  69. } */
  70. .pay_name {
  71. width: 6.2rem;
  72. height: 0.9rem;
  73. margin: 0.5rem 0 0.5rem 0;
  74. display: flex;
  75. justify-content: space-between;
  76. align-items: center;
  77. }
  78. .pay_name_left {
  79. height: 100%;
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. justify-content: space-between;
  84. }
  85. .pay_name_left_top {
  86. font-size: 0.34rem;
  87. font-weight: 600;
  88. color: #333333;
  89. }
  90. .pay_name_left_bottom {
  91. font-size: 0.26rem;
  92. font-weight: 400;
  93. color: #999999;
  94. }
  95. .pay_name_right {
  96. width: 0.9rem;
  97. height: 0.9rem;
  98. background: #D8D8D8;
  99. border: 0.01rem solid #979797;
  100. }
  101. .pay_name_right img{
  102. width: 100%;
  103. height: 100%;
  104. display: block;
  105. }
  106. input::-webkit-input-placeholder {
  107. /*WebKit browsers*/
  108. color: #999999;
  109. font-size: 0.4rem;
  110. margin-top: 13rem;
  111. }
  112. input::-moz-input-placeholder {
  113. /*Mozilla Firefox*/
  114. color: #999999;
  115. font-size: 0.4rem;
  116. margin-top: 13rem;
  117. }
  118. input::-ms-input-placeholder {
  119. /*Internet Explorer*/
  120. color: #999999;
  121. font-size: 0.4rem;
  122. margin-top: 13rem;
  123. }
  124. .pay_input {
  125. width: 100%;
  126. height: 3.48rem;
  127. background: #FFFFFF;
  128. border-radius: 0.16rem;
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. justify-content: space-between;
  133. }
  134. .pay_input-top {
  135. width: 6.36rem;
  136. height: 2.63rem;
  137. border-bottom: 0.01rem solid #E5E5E5;
  138. }
  139. .pay_input-top-shifu {
  140. margin: 0.54rem 0 0 0.41rem;
  141. font-size: 0.26rem;
  142. font-weight: 400;
  143. color: #333333;
  144. }
  145. .pay_input-top-manei {
  146. margin: 0.12rem 0 0 0.41rem;
  147. height: 1.19rem;
  148. display: flex;
  149. align-items: center;
  150. }
  151. .pay_input-top-manei span {
  152. font-size: 0.64rem;
  153. font-weight: 600;
  154. color: #333333;
  155. }
  156. .pay_input-top-manei input {
  157. width: 100%;
  158. height: 0.99rem;
  159. border: none;
  160. outline: medium;
  161. margin-left: 0.27rem;
  162. font-size: 1.1rem;
  163. }
  164. .pay_input-bottom {
  165. width: 6.36rem;
  166. height: 0.84rem;
  167. display: flex;
  168. justify-content: center;
  169. align-items: center;
  170. font-size: 0.24rem;
  171. font-weight: 400;
  172. color: #FE0032;
  173. }
  174. .pay_input-bottom-left {
  175. width: 0.3rem;
  176. height: 0.3rem;
  177. }
  178. .pay_input-bottom-left img {
  179. width: 100%;
  180. height: 100%;
  181. display: block;
  182. }
  183. .pay_input-bottom-right {
  184. margin-left: 0.08rem;
  185. }
  186. .pay_bottom {
  187. width: 6.86rem;
  188. height: 0.88rem;
  189. background: linear-gradient(179deg, #FE7577 0%, #FE0032 100%);
  190. border-radius: 1rem;
  191. position: fixed;
  192. bottom: 0.68rem;
  193. text-align: center;
  194. line-height: 0.88rem;
  195. font-size: 0.32rem;
  196. font-weight: 600;
  197. color: #FFFFFF;
  198. }
  199. </style>
  200. </head>
  201. <body>
  202. <div id="pay">
  203. <!-- <div class="pay_header">
  204. <div class="pay-header-nei">
  205. <div class="pay-header-nei-left">
  206. <img src="https://cdn.bjtdba.com/vod/image/2022-10-18/20221018150019704.png" alt="">
  207. </div>
  208. <div class="pay-header-nei-in">向商家付款</div>
  209. </div>
  210. </div> -->
  211. <div class="pay_name">
  212. <div class="pay_name_left">
  213. <div class="pay_name_left_top">付款给商家</div>
  214. <div class="pay_name_left_bottom" id="mername"></div>
  215. </div>
  216. <div class="pay_name_right">
  217. <img src="" id="merbanner" alt="">
  218. </div>
  219. </div>
  220. <div class="pay_input">
  221. <div class="pay_input-top">
  222. <div class="pay_input-top-shifu">实付金额</div>
  223. <div class="pay_input-top-manei">
  224. <span>¥</span>
  225. <input type="text" id="textInput" placeholder="请输入金额" maxLength="8"
  226. onkeyup="value=value.replace(/[^\d^\.]+/g,'')" oninput="myFunction()">
  227. </div>
  228. </div>
  229. <div class="pay_input-bottom">
  230. <div class="pay_input-bottom-left">
  231. <img src="https://cdn.bjtdba.com/vod/image/2022-10-18/20221018152247280.png" alt="">
  232. </div>
  233. <div class="pay_input-bottom-right">储蓄保全国合作伙伴招募中</div>
  234. </div>
  235. </div>
  236. <div class="pay_bottom" onclick="btn()">立即支付</div>
  237. </div>
  238. <script type="text/javascript">
  239. var ua = window.navigator.userAgent.toLowerCase();
  240. var Wxuserinfor;//微信user
  241. var mer_id;//商户Id
  242. var money;//金额
  243. var trade_type;//微信|支付宝
  244. //动态获取金额
  245. function myFunction() {
  246. console.log($("#textInput").val());
  247. money = $("#textInput").val()
  248. }
  249. //获取参数
  250. var userpay = parseParms()
  251. get_mer_info()//调用二维码接口
  252. //跳转微信授权登陆
  253. let local = window.location.href;
  254. if (local.split(':')[0] == 'http') {
  255. local = local.split(':')[0] + 's:' + local.split(':')[1]
  256. console.log(local)
  257. } else {
  258. local = window.location.href;
  259. }
  260. let wechatHrefurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + 'wx66f5f8def2b755da' +
  261. "&redirect_uri=" + encodeURIComponent(local) +
  262. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  263. //不是微信并且不是支付宝
  264. if (ua.match(/MicroMessenger/i) != "micromessenger" && ua.match(/AlipayClient/i) != "alipayclient") {
  265. alert('请使用微信或支付宝扫码');
  266. }
  267. //判断是不是微信
  268. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  269. console.log(userpay)
  270. trade_type="WX"
  271. if (userpay.code == "" || userpay.code == null) {
  272. window.location.href = wechatHrefurl;
  273. } else {
  274. user()
  275. }
  276. }
  277. //判断是不是支付宝
  278. if (ua.match(/AlipayClient/i) == "alipayclient") {
  279. console.log(userpay)
  280. trade_type="ALI"
  281. if (userpay.code == null || userpay.code == "") {
  282. local = local.replace('#/', '');
  283. let aliHrefurl =
  284. "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021001197698727&scope=auth_user&redirect_uri=" +
  285. encodeURIComponent(local)
  286. window.location.href = aliHrefurl;
  287. } else {
  288. aliUser()
  289. }
  290. }
  291. //获取二维码
  292. function get_mer_info() {
  293. $.post("https://test.bjtdba.com/api/merchantcheckcodeid/" + userpay.id, function (data) {
  294. if (data.status == 200) {
  295. if (data.data.code == 1) {
  296. mer_id = data.data.mer_id; //获取店铺id
  297. getQrcode(data)
  298. } else {
  299. //如果不可以收款清空body
  300. alert("商户未开通")
  301. $("body").html("")
  302. }
  303. } else {
  304. alert(data.message)
  305. //400收款清空body
  306. $("body").html("")
  307. }
  308. })
  309. }
  310. //获取商户信息
  311. function getQrcode(event) {
  312. $.get("https://test.bjtdba.com/api/merchant/get_mer_info", { mer_id: event.data.mer_id }, function (data) {
  313. console.log(data, "商户信息")
  314. if(data.status==200){
  315. $("#mername").text(data.data.mer_name)//商户头像
  316. $("#merbanner").attr("src",data.data.mer_banner)//商户头像
  317. }
  318. })
  319. }
  320. //wx获取用户信息
  321. function user() {
  322. $.get("https://test.bjtdba.com/api/wechat/wechatAuthorization", { code: userpay.code }, function (data) {
  323. if (data.status == 200) {
  324. Wxuserinfor = data.data
  325. console.log(Wxuserinfor, "接口")
  326. }
  327. })
  328. }
  329. //支付宝获取用户信息
  330. function aliUser() {
  331. $.get("https://test.bjtdba.com/api/ali/aliSign", { code: userpay.code }, function (data) {
  332. console.log(data, '支付宝用户信息')
  333. })
  334. }
  335. //点击支付创建订单
  336. function btn() {
  337. console.log(Wxuserinfor, '微信用户信息')
  338. let data = {
  339. mer_id: mer_id,
  340. money: money,
  341. trade_type: trade_type,
  342. }
  343. if (trade_type == 'WX') {
  344. data.avatar = Wxuserinfor.headimgurl;
  345. data.nickname = Wxuserinfor.nickname;
  346. data.pay_user_id = Wxuserinfor.unionid;
  347. } else if (trade_type == 'ALI') {
  348. }
  349. $.post("https://test.bjtdba.com/api/merchant/createOrder", { data }, function (data) {
  350. console.log(data, '订单创建')
  351. })
  352. }
  353. //hash参数转对象
  354. function parseParms() {
  355. var str = window.location.href.split("?")[1];
  356. var pieces = str.split("&"), data = {}, i, parts;
  357. // process each query pair
  358. for (i = 0; i < pieces.length; i++) {
  359. parts = pieces[i].split("=");
  360. if (parts.length < 2) {
  361. parts.push("");
  362. }
  363. data[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
  364. }
  365. return data
  366. }
  367. </script>
  368. </body>
  369. </html>