电脑网站支付/手机网站支付
一般服务端都会用post请求,也就是返回的form表单,示例如下:
<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&format=json&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&app_id=2017060101317939&sign_type=RSA2×tamp=2014-07-24+03%3A07%3A50">
<input type="hidden" name="biz_content" value="{"time_expire":"2016-12-31 10:05:01","extend_params":"","query_options":"[\"hyb_amount\",\"enterprise_pay_info\"]","settle_info":"","subject":"Iphone6 16G","product_code":"FAST_INSTANT_TRADE_PAY","body":"Iphone6 16G","qr_pay_mode":"1","integration_type":"PCWEB","merchant_order_no":"20161008001","sub_merchant":"","invoice_info":"","ext_user_info":"","timeout_express":"90m","disable_pay_channels":"pcredit,moneyFund,debitCardExpress","agreement_sign_params":"","royalty_info":"","store_id":"NJ_001","request_from_url":"https://","qrcode_width":"100","goods_detail":"","enable_pay_channels":"pcredit,moneyFund,debitCardExpress","out_trade_no":"20150320010101001","total_amount":"88.88","business_params":"{\"mc_create_trade_ip\":\"127.0.0.1\"}","promo_params":"{\"storeIdType\":\"1\"}"}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>
前端展示的方式分为两种
第一种
const div = document.createElement('formdiv');
div.innerHTML = data.data.form;
document.body.appendChild(div);
document.forms['根据服务端返回的form表单的name同步'].setAttribute('target', '_self');
document.forms['根据服务端返回的form表单的name同步'].submit();
div.remove();
这里的data.data.form 是服务端返回的form表单 setAttribute('target', '_self'); tartget 设置为self,是为了兼容 safari浏览器 以及其他兼容问题
第二种
var iframe = document.createElement('iframe');
// 设置iframe的属性
iframe.width = '500'; // 设置宽度
iframe.height = '500'; // 设置高度
iframe.srcdoc = 服务端返回的form表单;
document.body.appendChild(iframe);
这个展示可能不太友好, 可以根据业务需求展示成弹框也可以 , 手机网站支付一般都展示第一种方式