手机网页支付宝支付api https://opendocs.alipay.com/open/203/105285
引用支付宝sdk
支付配置
/// <summary> /// 手机网页支付配置 /// </summary> public class MobileConfig { // 应用ID,您的APPID public static string app_id = AlipayData.AppId; // 支付宝网关 正式:https://openapi.alipay.com/gateway.do 沙箱: https://openapi.alipaydev.com/gateway.do public static string gatewayUrl = AlipayData.GatewayUrl; // 商户私钥,您的原始格式RSA私钥 public static string private_key = AlipayData.Privatekey; // 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。 public static string alipay_public_key = AlipayData.AlipayPublicKey; //参数返回格式,只支持json public static string format = "json"; //调用的接口版本,固定为:1.0 版本 public static string version = "1.0"; // 签名方式 public static string sign_type = "RSA2"; // 编码格式 public static string charset = "UTF-8"; // false 表示不从文件加载密钥 public static bool keyFromFile = false; }
控制器
/// <summary> /// 手机网页支付宝支付 /// </summary> /// <returns></returns> public ActionResult Alipay() { #region 支付操作 //////////////////////////////////////////请求参数///////////////必填参数///////////////////////////////// var payOrderNo = "1234567890"; var orderPrice = 0.01; var name = "iphone X"; var guidCode = CookiesHelper.GetCookie(CacheName.XinJiangPay + "GUID"); if (string.IsNullOrEmpty(payOrderNo)) { return Json(new { Success = false, Msg = "支付订单号无效!", JsonRequestBehavior.AllowGet }); } //商家网站唯一订单号。 OrderIDNum string out_trade_no = payOrderNo; //+ "_" + Global.StudentSfCoding; //商品的标题/交易标题/订单标题/订单关键字等。不可使用特殊字符,如 /,=,& 等。 所购买的专业 string subject = name; //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里 购买人的姓名、身份证号 string body = ""; //订单总金额,单位为元,精确到小数点后两位,取值范围:[0.01,100000000] 。 string total_amount = orderPrice.ToString(); //Request["money"]; //用户付款中途退出返回商户网站的地址 string quit_url = ""; //////////////////////////////////////////////////////////////////////////////////////////////// //把请求参数打包成数组 Dictionary<string, object> bizContent = new Dictionary<string, object>(); bizContent.Add("out_trade_no", out_trade_no); bizContent.Add("subject", subject); bizContent.Add("body", body); bizContent.Add("total_amount", total_amount); bizContent.Add("quit_url", quit_url); string return_url = ConfigHelper.Domain + "/callback/return_url"; string notifi_url = ConfigHelper.Domain + "/callback/notify_url"; Service ali = new Service(); string sHtmlText = ali.QUICK_WAP_WAY(bizContent, return_url, notifi_url); return Json(new { Success = true, data = sHtmlText }); #endregion }
Service 请求支付宝接口
public class Service { #region 手机网页支付 /// <summary> /// 构造接口 /// </summary> /// <returns>表单提交HTML信息</returns> public string QUICK_WAP_WAY(Dictionary<string, object> bizContent, string returnUrl, string notifyUrl) { bizContent.Add("product_code", "QUICK_WAP_WAY"); IAopClient client = new DefaultAopClient(MobileConfig.gatewayUrl, MobileConfig.app_id, MobileConfig.private_key, MobileConfig.format, MobileConfig.version, MobileConfig.sign_type, MobileConfig.alipay_public_key, MobileConfig.charset, MobileConfig.keyFromFile); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.SetNotifyUrl(notifyUrl); request.SetReturnUrl(returnUrl); string Contentjson = JsonConvert.SerializeObject(bizContent); request.BizContent = Contentjson; AlipayTradeWapPayResponse response = client.pageExecute(request); var strHtml = response.Body; strHtml = strHtml.Replace("<input ", "<input type='hidden'");//返回的form表单将input隐藏一下 return strHtml; } #endregion }
标签:MobileConfig,支付宝,string,C#,bizContent,url,static,2.0,public From: https://www.cnblogs.com/mtjj/p/17201303.html