C#支付寶支付接口H5版(手機網頁支付)

接口官方文檔 https://docs.open.alipay.com/203/107090/javascript

 

首先在Nuget 安裝 Alipayhtml

     /// <summary>
        /// 支付寶支付
        /// </summary>
        /// <param name="model"></param>
        /// <param name="configPath"></param>
        /// <returns></returns>
        public static string Alipay()
        {
            string OrderNumber = "alipay" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string app_id = "你的app_id";
            string merchant_private_key = "你的應用私鑰";
            string alipay_public_key = "你的支付寶公鑰";
            string timeout_express = "30m";//訂單有效時間(分鐘)
            string postUrl = "https://openapi.alipay.com/gateway.do";
            string sign_type = "RSA2";//加簽方式 有兩種RSA和RSA2 我這裏使用的RSA2(支付寶推薦的)
            string version = "1.0";//固定值 不用改
            string format = "json";//固定值
            string Amount = "0.01";//訂單金額
            string method = "QUICK_WAP_WAY";//調用接口 固定值 不用改
            IAopClient client = new DefaultAopClient(postUrl, app_id, merchant_private_key, format, version, sign_type, alipay_public_key, "UTF-8", false);
            AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
            request.SetNotifyUrl("支付寶後臺通知的地址");
            request.SetReturnUrl("支付寶前臺回跳的地址");
            request.BizContent = "{" +
            "    \"body\":\"對一筆交易的具體描述信息。若是是多種商品,請將商品描述字符串累加傳給body。\"," +
            "    \"subject\":\"商品描述\"," +
            "    \"out_trade_no\":\"商家惟一訂單,填寫你項目裏生成的惟一訂單號\"," +
            "    \"timeout_express\":\"" + timeout_express + "\"," +
            "    \"total_amount\":" + Amount + "," +
            "    \"product_code\":\""+ method + "\"" +
            "  }";
            AlipayTradeWapPayResponse response = client.pageExecute(request);
            string form = response.Body.Substring(0, response.Body.IndexOf("<script>"));
            return form;
        }
 
 

<!DOCTYPE html>java


<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<title></title>
<script type="text/javascript">
function submit(){
document.forms['alipaysubmit'].submit();
}
</script>
</head>
<body>
<div>
<button onclick="submit()">支付寶支付</button>
<div id="formDiv" style="display:none;">
<!--form-->

</div>

</div>
</body>
</html>express

相關文章
相關標籤/搜索