| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
- <title>向商家付款</title>
- <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
- <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
- <script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>
- <script type="text/javascript">
- function adapter() {
- const dpWidth = document.documentElement.clientWidth
- const rootFonstSize = (dpWidth * 100) / 750
- 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))) {
- document.documentElement.style.fontSize = rootFonstSize + 'px'
- } else {
- document.documentElement.style.fontSize = dpWidth
- }
- }
- adapter()
- window.onresize = adapter
- </script>
- <style>
- body {
- background: #F8F8F8;
- }
- * {
- margin: 0;
- padding: 0;
- }
- #pay {
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- /* .pay_header {
- width: 100%;
- height: 1.76rem;
- display: flex;
- justify-content: center;
- align-items: center;
- background: #FFFFFF;
- }
- .pay-header-nei {
- width: 6.86rem;
- height: 100%;
- display: flex;
- }
- .pay-header-nei-in {
- margin-top: 1.07rem;
- font-size: 0.36rem;
- font-weight: 500;
- color: #333333;
- text-align: center;
- margin-left: 2.17rem;
- }
- .pay-header-nei-left {
- width: 0.36rem;
- height: 0.36rem;
- margin-top: 1.17rem;
- }
- .pay-header-nei-left img {
- width: 100%;
- height: 100%;
- display: block;
- } */
- .pay_name {
- width: 6.2rem;
- height: 0.9rem;
- margin: 0.5rem 0 0.5rem 0;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .pay_name_left {
- height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: space-between;
- }
- .pay_name_left_top {
- font-size: 0.34rem;
- font-weight: 600;
- color: #333333;
- }
- .pay_name_left_bottom {
- font-size: 0.26rem;
- font-weight: 400;
- color: #999999;
- }
- .pay_name_right {
- width: 0.9rem;
- height: 0.9rem;
- background: #D8D8D8;
- border: 0.01rem solid #979797;
- }
- .pay_name_right img{
- width: 100%;
- height: 100%;
- display: block;
- }
- input::-webkit-input-placeholder {
- /*WebKit browsers*/
- color: #999999;
- font-size: 0.4rem;
- margin-top: 13rem;
- }
- input::-moz-input-placeholder {
- /*Mozilla Firefox*/
- color: #999999;
- font-size: 0.4rem;
- margin-top: 13rem;
- }
- input::-ms-input-placeholder {
- /*Internet Explorer*/
- color: #999999;
- font-size: 0.4rem;
- margin-top: 13rem;
- }
- .pay_input {
- width: 100%;
- height: 3.48rem;
- background: #FFFFFF;
- border-radius: 0.16rem;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: space-between;
- }
- .pay_input-top {
- width: 6.36rem;
- height: 2.63rem;
- border-bottom: 0.01rem solid #E5E5E5;
- }
- .pay_input-top-shifu {
- margin: 0.54rem 0 0 0.41rem;
- font-size: 0.26rem;
- font-weight: 400;
- color: #333333;
- }
- .pay_input-top-manei {
- margin: 0.12rem 0 0 0.41rem;
- height: 1.19rem;
- display: flex;
- align-items: center;
- }
- .pay_input-top-manei span {
- font-size: 0.64rem;
- font-weight: 600;
- color: #333333;
- }
- .pay_input-top-manei input {
- width: 100%;
- height: 0.99rem;
- border: none;
- outline: medium;
- margin-left: 0.27rem;
- font-size: 1.1rem;
- }
- .pay_input-bottom {
- width: 6.36rem;
- height: 0.84rem;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 0.24rem;
- font-weight: 400;
- color: #FE0032;
- }
- .pay_input-bottom-left {
- width: 0.3rem;
- height: 0.3rem;
- }
- .pay_input-bottom-left img {
- width: 100%;
- height: 100%;
- display: block;
- }
- .pay_input-bottom-right {
- margin-left: 0.08rem;
- }
- .pay_bottom {
- width: 6.86rem;
- height: 0.88rem;
- background: linear-gradient(179deg, #FE7577 0%, #FE0032 100%);
- border-radius: 1rem;
- position: fixed;
- bottom: 0.68rem;
- text-align: center;
- line-height: 0.88rem;
- font-size: 0.32rem;
- font-weight: 600;
- color: #FFFFFF;
- }
- </style>
- </head>
- <body>
- <div id="pay">
- <!-- <div class="pay_header">
- <div class="pay-header-nei">
- <div class="pay-header-nei-left">
- <img src="https://cdn.bjtdba.com/vod/image/2022-10-18/20221018150019704.png" alt="">
- </div>
- <div class="pay-header-nei-in">向商家付款</div>
- </div>
- </div> -->
- <div class="pay_name">
- <div class="pay_name_left">
- <div class="pay_name_left_top">付款给商家</div>
- <div class="pay_name_left_bottom" id="mername"></div>
- </div>
- <div class="pay_name_right">
- <img src="" id="merbanner" alt="">
- </div>
- </div>
- <div class="pay_input">
- <div class="pay_input-top">
- <div class="pay_input-top-shifu">实付金额</div>
- <div class="pay_input-top-manei">
- <span>¥</span>
- <input type="text" id="textInput" placeholder="请输入金额" maxLength="8"
- onkeyup="value=value.replace(/[^\d^\.]+/g,'')" oninput="myFunction()">
- </div>
- </div>
- <div class="pay_input-bottom">
- <div class="pay_input-bottom-left">
- <img src="https://cdn.bjtdba.com/vod/image/2022-10-18/20221018152247280.png" alt="">
- </div>
- <div class="pay_input-bottom-right">储蓄保全国合作伙伴招募中</div>
- </div>
- </div>
- <div class="pay_bottom" onclick="btn()">立即支付</div>
- </div>
- <script type="text/javascript">
- var ua = window.navigator.userAgent.toLowerCase();
- var Wxuserinfor;//微信user
- var mer_id;//商户Id
- var money;//金额
- var trade_type;//微信|支付宝
- //动态获取金额
- function myFunction() {
- console.log($("#textInput").val());
- money = $("#textInput").val()
- }
- //获取参数
- var userpay = parseParms()
- get_mer_info()//调用二维码接口
- //跳转微信授权登陆
- let local = window.location.href;
- if (local.split(':')[0] == 'http') {
- local = local.split(':')[0] + 's:' + local.split(':')[1]
- console.log(local)
- } else {
- local = window.location.href;
- }
- let wechatHrefurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + 'wx66f5f8def2b755da' +
- "&redirect_uri=" + encodeURIComponent(local) +
- "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
- //不是微信并且不是支付宝
- if (ua.match(/MicroMessenger/i) != "micromessenger" && ua.match(/AlipayClient/i) != "alipayclient") {
- alert('请使用微信或支付宝扫码');
- }
- //判断是不是微信
- if (ua.match(/MicroMessenger/i) == "micromessenger") {
- console.log(userpay)
- trade_type="WX"
- if (userpay.code == "" || userpay.code == null) {
- window.location.href = wechatHrefurl;
- } else {
- user()
- }
- }
- //判断是不是支付宝
- if (ua.match(/AlipayClient/i) == "alipayclient") {
- console.log(userpay)
- trade_type="ALI"
- if (userpay.code == null || userpay.code == "") {
- local = local.replace('#/', '');
- let aliHrefurl =
- "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021001197698727&scope=auth_user&redirect_uri=" +
- encodeURIComponent(local)
- window.location.href = aliHrefurl;
- } else {
- aliUser()
- }
- }
- //获取二维码
- function get_mer_info() {
- $.post("https://test.bjtdba.com/api/merchantcheckcodeid/" + userpay.id, function (data) {
- if (data.status == 200) {
- if (data.data.code == 1) {
- mer_id = data.data.mer_id; //获取店铺id
- getQrcode(data)
- } else {
- //如果不可以收款清空body
- alert("商户未开通")
- $("body").html("")
- }
- } else {
- alert(data.message)
- //400收款清空body
- $("body").html("")
- }
- })
- }
- //获取商户信息
- function getQrcode(event) {
- $.get("https://test.bjtdba.com/api/merchant/get_mer_info", { mer_id: event.data.mer_id }, function (data) {
- console.log(data, "商户信息")
- if(data.status==200){
- $("#mername").text(data.data.mer_name)//商户头像
- $("#merbanner").attr("src",data.data.mer_banner)//商户头像
- }
- })
- }
- //wx获取用户信息
- function user() {
- $.get("https://test.bjtdba.com/api/wechat/wechatAuthorization", { code: userpay.code }, function (data) {
- if (data.status == 200) {
- Wxuserinfor = data.data
- console.log(Wxuserinfor, "接口")
- }
- })
- }
- //支付宝获取用户信息
- function aliUser() {
- $.get("https://test.bjtdba.com/api/ali/aliSign", { code: userpay.code }, function (data) {
- console.log(data, '支付宝用户信息')
- })
- }
- //点击支付创建订单
- function btn() {
- console.log(Wxuserinfor, '微信用户信息')
- let data = {
- mer_id: mer_id,
- money: money,
- trade_type: trade_type,
- }
- if (trade_type == 'WX') {
- data.avatar = Wxuserinfor.headimgurl;
- data.nickname = Wxuserinfor.nickname;
- data.pay_user_id = Wxuserinfor.unionid;
- } else if (trade_type == 'ALI') {
-
- }
- $.post("https://test.bjtdba.com/api/merchant/createOrder", { data }, function (data) {
- console.log(data, '订单创建')
- })
- }
- //hash参数转对象
- function parseParms() {
- var str = window.location.href.split("?")[1];
- var pieces = str.split("&"), data = {}, i, parts;
- // process each query pair
- for (i = 0; i < pieces.length; i++) {
- parts = pieces[i].split("=");
- if (parts.length < 2) {
- parts.push("");
- }
- data[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
- }
- return data
- }
- </script>
- </body>
- </html>
|