首页 > 编程语言 >C# 手机网页支付宝支付2.0

C# 手机网页支付宝支付2.0

时间:2023-03-09 20:34:30浏览次数:49  
标签:MobileConfig 支付宝 string C# bizContent url static 2.0 public

 

手机网页支付宝支付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

相关文章

  • burpsuite_pro_v2.0beta 下载和安装使用过程
    burpsuite_pro_v2.0beta使用过程 下载地址:https://pan.baidu.com/s/1mJdRZqSr5A0W9aWEcs3ySg密码:293x  (压缩包内已包含注册机Loader) java8181下载地址:htt......
  • Comparable和Comparator的区别
    一、Comparable与Comparator的相同点Comparable和Comparator都是java的一个接口,多用于实现集合中元素的比较及排序。当我们自定义一个类时,如果需要规定其中的排序规则时,......
  • ArchKeeper(开篇):架构守护平台的问题与理念
    作者:京东科技倪新明在敏捷开发环境下,系统通过迭代增量的交付价值,系统架构也是如此。团队不可能在项目之初就建立完美的系统架构,系统架构应该随着系统迭代不断演进。架构演......
  • 关于在SSM项目中使用mybatis-plus时控制台出现was not registered for synchronizatio
    1.出现这个问题可能会出现事务不同步的问题导致无法进行数据库的连接。可以在service层中添加@Tranational注解2.这里我解决是添加配置文件log4j的配置文件查看是数据库连......
  • Linux安装docker-compose
    Linux环境:centos7.61.安装curl-L"https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname-s)-$(uname-m)"-o/usr/local/bin/docker-......
  • maven 遇到Cannot resolve javax.servlet:servlet-api:3.1
    报错Cannotresolvejavax.servlet:servlet-api:3.1原因<dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>......
  • SiC MOSFET 高频开关下的损耗抑制
    实验环境如下:图-1图-2图-3使用IVCR1401芯片驱动SiCMOSFET,使用n122U31做电气隔离。VCC经过调压器整流过后为100V直流电压。在100kHZ的频率下......
  • postgresql 查询当前schema下所有表数据的数量
    查询当前数据库下所有表的数据量,后来改成了通过sql拼接sql语句来查询。SELECTconcat('select''',tablename,'''astable_name,count(1)assumfrom',tablename,'un......
  • AspNet Core: Jwt身份认证
    目录AspNetCore:Jwt身份认证资源服务器创建项目依赖包添加APIProgram认证服务器创建项目依赖包AspNetCore:Jwt身份认证资源服务器创建项目新建一个“AspNetCoreWe......
  • 浅谈 Axios 和 Fetch 的区别
    1.简单区分   2.请求方式axios传一个对象,里面包含请求url和请求方法,参数。fetch传两个参数,第一个是请求url,第二个是请求的一些参数。//axios请求:constoptio......