隐藏

C#支付宝支付接口H5版(手机网页支付)

发布:2021/11/15 10:10:38作者:管理员 来源:本站 浏览次数:912

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="alipay.aspx.cs" Inherits="qrcode_alipay" %>
<!DOCTYPE html>


<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>



using Aop.Api;

using Aop.Api.Request;
using Aop.Api.Response;
using Maticsoft.Fn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class qrcode_alipay : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Maticsoft.Model.SEO_ServiceOrder _ServiceOrder = new Maticsoft.Model.SEO_ServiceOrder();
        _ServiceOrder = _bll_SEO_ServiceOrder.GetModelList(string.Format("SsOrderid='{0}'", orderid)).FirstOrDefault();
        if (_ServiceOrder == null)
        {
            Response.Redirect("/404.html");
            Response.End();
        }

        Response.Write(Alipay(_ServiceOrder));
    }
    /// <summary>
    /// 支付宝支付
    /// </summary>
    /// <param name="model"></param>
    /// <param name="configPath"></param>
    /// <returns></returns>
    public static string Alipay(Maticsoft.Model.SEO_ServiceOrder _ServiceOrder)
    {
        string OrderNumber = "alipay" + DateTime.Now.ToString("yyyyMMddHHmmss");
        string app_id = config.app_id;
        string merchant_private_key = config.private_key;
        string alipay_public_key = config.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("http://www.*****.com/Handler/Notify_url.aspx");//支付宝后台通知的地址
        request.SetReturnUrl("");//支付宝前台回跳的地址
        request.BizContent = "{" +
        "    \"body\":\"" + _ServiceOrder.Title + "\"," +
        "    \"subject\":\"" + _ServiceOrder.Title + "\"," +
        "    \"out_trade_no\":\"" + _ServiceOrder.SsOrderid + "\"," +
        "    \"timeout_express\":\"" + timeout_express + "\"," +
        "    \"total_amount\":" + _ServiceOrder.PaidTotalPrice + "," +
        "    \"product_code\":\"" + method + "\"" +
        "  }";
        AlipayTradeWapPayResponse response = client.pageExecute(request);
        string form = response.Body.Substring(0, response.Body.IndexOf("<script>"));
        return form;
    }

}