如何使用沙箱测试扫码支付(.net版)

说明: 
本帖是利用支付宝沙箱测试当面付支付接口,不是官方demo,是我自己写的简版示例,以及我的沙箱账号密钥,仅供参考测试用
测试环境:适用于Visual studio 2010及以上版本、Framework3.5及以上版本的开发环

文档地址:查看

sdk:下载

官方demo:下载

.net接口测试必须生成私钥pkcs1的私钥,不能用pkcs8的!!!!!

沙箱参数获取地址:查看

沙箱环境测试,必须使用安卓手机扫码下载沙箱版钱包进行测试;

正式环境测试参数配置请参考:[url]https://openclub.alipay.com/read.php?tid=1606&fid=25[/url]

基本参数配置:

 public class Config    {        //沙箱支付宝公钥        public static string alipay_public_key = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnVuBUzhfo7kWUN/TS/kHmb4afsAlUVaTR3U5e74V0os1bzlfvh+cpwnwzaEIb36CR1OzeIIzXgARIW/zGAL1/PLG8dFEXQOIGkA0a8YXGVNX9KeWnFCnCQ5gQxrfJ3ryasXzWBxv5bex1VrVsQ2TZ1VdUD+S7dR4SWFHvyck8/xGt3Hz5peUqo/OIlfQpoTBXdqfnJNrTVAMqcQhrIWwgpSVgmUq+UhlZsDaiUvxWWFm9v9nY172jFfzup/DIET//OpIghL6AB2F+ywkCcHdZHiGklnpNoQKQ6XMVKaO/k2nlHU64Y4WGSgJnSG6B798ohZoi3pndrVPAH5+5BKEFQIDAQAB";        //开发者原始私钥,千万不要用pkcs8格式的 沙箱        public static string merchant_private_key = @"MIIEowIBAAKCAQEA3wwVCYWsOOnJPDB3HCAVz7dlEjrwkWdHUDWWcAtBJmb3Jy9vjVMqCTG4HFd1OaOsAKWo5KYm3/VJK7WICN/xmYToM38x9CCWAF5mAhJ4jPgpeYqSFoWNFv7PrjURjXV7zZZHrTTXFagL5CmXXB89tzetAV7L43UfgSf56dglJq/Tgr9GqqsDjtfdKzrmb1WhQiQ+Sw5rwxXVz86yR3DgMmI29oYSSFreZ+KP29yzGHrsX8FrkOFZRsfrNMGSdbnVMgF/F/G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o/vW7UOMgBcCPus5sy+21D7eElBltKBV3n8GtM6WQwwFmcc8QKjXj2j0iIADlArRAoGBAPM8kqdFHQUEDhCbk1CZR4H/hStI1DERFQYvQkIGyvIhf4Q5gN+AeM9CQpFhLBqI4kt0u9mSQV8a2fEaMCRqi7jWR1AA/nhM46AYWTiH59kdAaNlAGQHuqcBEc6jhBFS8gRMRFd/qpA8CHsMeJYIRQkKcITukjVo+KaUoF4e1wLL";        //应用appId沙箱       public static string appId = "2016101800718925";        public static string format = "json";        //支付宝网关        public static string serverUrl = "https://openapi.alipay.com/gateway.do";           //编码,无需修改        public static string charset = "utf-8";        //签名类型,支持RSA2(推荐!)、RSA        public static string sign_type = "RSA2";        //版本号,无需修改        public static string version = "1.0";        ///         /// 私钥文件类型转换成纯文本类型        ///         /// 过滤后的字符串类型私钥        public static string getMerchantPriveteKeyStr()        {            StreamReader sr = new StreamReader(merchant_private_key);            string pubkey = sr.ReadToEnd();            sr.Close();            if (pubkey != null)            {                pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");                pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");                pubkey = pubkey.Replace("\r", "");                pubkey = pubkey.Replace("\n", "");            }            return pubkey;        }

 

接口调用

 static void Main(string[] args)        {            IAopClient client = new DefaultAopClient("https://openapi.alipaydev.com/gateway.do", Com.Alipay.Config.appId, Com.Alipay.Config.merchant_private_key, "json", "1.0", "RSA2", Com.Alipay.Config.alipay_public_key, "GBK", false);            AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();            AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();            model.OutTradeNo = "2018090515181234561234123";            model.Subject = "扫码支付测试";            model.TotalAmount = "0.01";            request.SetBizModel(model);            AlipayTradePrecreateResponse response = client.Execute(request);            Console.WriteLine("接口调用返回信息:"+response.Body);            Console.WriteLine("二维码码串:" + response.QrCode);        }

注:

qr_code_timeout_express  ,二维码有效时间最小为2m,设置为1m会错报错“二维码已失效,请联系商户重新支付”

 

返回结果

接口调用返回信息:{"alipay_trade_precreate_response":{"code":"10000","msg":"Sucess","out_trade_no":"2018090515181234561234123","qr_code":"https:\/\/qr.alipay.om\/bax01197gcaewlgo7d3t00ec"},"sign":"BgsUNGYseIpcIhMhx0s9y7Y/mq+O2rcRwx5ksteOrd/Kjd35jlEVzkvp6CFoBAQWIfAzO5dVAKuvTemHuAO1Y/qa+OeoBPgeqeFdI3mjZ0/nvG847gf8Go20bTR0Gkw8ccPoDbPABP2HHUZkbvugpD0vlY2ZnqzfPkq+i7cYeEtXlXy9IvwZo4PRAkoPN+laexYhNBbSmiOm44bFVUC2ZuST2aJKvNPvf5eW8ZCPrN3SExbf4AXB1jFA355tZD2D3aBqPLSFdAZ1gFbxwwxQ1ULemYLO+T6zC3ZkEwSbwIlx28ct23KvsT9RZdhV+a97p4Vu83Sga1BcwoIJqA=="}二维码码串:[url]https://qr.alipay.com/bax01197gcaewlgo7d3t00ec[/url]

 

注:

QrCode:二维码码串,生成二维码串的默认有效期是两小时,开发者QrCode值后,放前台生成二维码,使用支付宝钱包扫码支付即可

 

 

 

 

上一篇:【C 语言】指针数据类型 ( 指针类型变量 与 指针指向的内存块 概念区别 | 指针赋值 | 指针运算 | 内存赋值 | 内存取值 | 内存修改注意事项 )


下一篇:数据仓库专题(24)-数据仓库架构体系总结