index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. trade_type = "WX"
  270. if (userpay.code == "" || userpay.code == null) {
  271. window.location.href = wechatHrefurl;
  272. } else {
  273. user()
  274. }
  275. }
  276. //判断是不是支付宝
  277. if (ua.match(/AlipayClient/i) == "alipayclient") {
  278. trade_type = "ALI"
  279. if (userpay.code == null || userpay.code == "") {
  280. local = local.replace('#/', '');
  281. let aliHrefurl =
  282. "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021001197698727&scope=auth_user&redirect_uri=" +
  283. encodeURIComponent(local)
  284. window.location.href = aliHrefurl;
  285. } else {
  286. aliUser()
  287. }
  288. }
  289. //获取二维码
  290. function get_mer_info() {
  291. $.post("https://test.bjtdba.com/api/merchantcheckcodeid/" + userpay.id, function (data) {
  292. if (data.status == 200) {
  293. if (data.data.code == 1) {
  294. mer_id = data.data.mer_id; //获取店铺id
  295. getQrcode(data)
  296. } else {
  297. //如果不可以收款清空body
  298. alert("商户未开通")
  299. $("body").html("")
  300. }
  301. } else {
  302. alert(data.message)
  303. //400收款清空body
  304. $("body").html("")
  305. }
  306. })
  307. }
  308. //获取商户信息
  309. function getQrcode(event) {
  310. $.get("https://test.bjtdba.com/api/merchant/get_mer_info", { mer_id: event.data.mer_id }, function (data) {
  311. if (data.status == 200) {
  312. $("#mername").text(data.data.mer_name)//商户头像
  313. $("#merbanner").attr("src", data.data.mer_banner)//商户头像
  314. }
  315. })
  316. }
  317. //wx获取用户信息
  318. function user() {
  319. $.get("https://test.bjtdba.com/api/wechat/wechatAuthorization", { code: userpay.code }, function (data) {
  320. if (data.status == 200) {
  321. Wxuserinfor = data.data
  322. }
  323. })
  324. }
  325. //支付宝获取用户信息
  326. function aliUser() {
  327. $.get("https://test.bjtdba.com/api/ali/aliSign", { code: userpay.code }, function (data) {
  328. console.log(data, '支付宝用户信息')
  329. })
  330. }
  331. //点击支付创建订单
  332. function btn() {
  333. console.log(Wxuserinfor, '微信用户信息')
  334. let data = {
  335. mer_id: mer_id,
  336. money: money,
  337. trade_type: trade_type,
  338. }
  339. if (trade_type == 'WX') {
  340. data.avatar = Wxuserinfor.headimgurl;
  341. data.nickname = Wxuserinfor.nickname;
  342. data.pay_user_id = Wxuserinfor.unionid;
  343. } else if (trade_type == 'ALI') {
  344. }
  345. $.post("https://test.bjtdba.com/api/merchant/createOrder", { mer_id: data.mer_id, trade_type: data.trade_type, avatar: data.avatar, nickname: data.nickname, pay_user_id: data.pay_user_id }, function (data) {
  346. console.log(data, '订单创建')
  347. if (data.status == 200) {
  348. jsapiPay(data.data)//订单数据
  349. } else {
  350. alert(data.message)
  351. //400收款清空body
  352. $("body").html("")
  353. }
  354. })
  355. }
  356. // 创建订单成功后调用接口区分微信支付还是支付宝,分别调用支付
  357. function jsapiPay(event) {
  358. $.post("https://test.bjtdba.com/api/merchant/jsapiPay", { out_trade_no: event.out_trade_no, type: 'HF' }, function (data) {
  359. console.log(data, '订单创建完区分WZ')
  360. if (data.status == 200) {
  361. if (trade_type == 'WX') {
  362. console.log("WX")
  363. } else if (trade_type == 'ALI') {
  364. console.log("ALI")
  365. }
  366. } else {
  367. alert(data.message)
  368. //400收款清空body
  369. $("body").html("")
  370. }
  371. })
  372. }
  373. //hash参数转对象
  374. function parseParms() {
  375. var str = window.location.href.split("?")[1];
  376. var pieces = str.split("&"), data = {}, i, parts;
  377. // process each query pair
  378. for (i = 0; i < pieces.length; i++) {
  379. parts = pieces[i].split("=");
  380. if (parts.length < 2) {
  381. parts.push("");
  382. }
  383. data[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
  384. }
  385. return data
  386. }
  387. </script>
  388. </body>
  389. </html>