当前位置:首页 > 芯闻号 > 充电吧
[导读]它现在这种支付方式比较多象网银在线等使用的方法都是url验证,就是通过url参数和一个这些url参数的md5编码来确认这个连接的正确性,支付宝在你购买成功后跳转自定义连接的时候会传2次过来,第一次是数

它现在这种支付方式比较多象网银在线等使用的方法都是url验证,就是通过url参数和一个这些url参数的md5编码来确认这个连接的正确性,支付宝在你购买成功后跳转自定义连接的时候会传2次过来,第一次是数据底层请求,第二次是web请求,而只有第一次有验证码,这个只能通过记录下来才看的到,因为两次请求间隔很小,如果光显示的话最后的结果是被第二次覆盖了的。所以在接收的时候就要设定接收条件,一种是没有notify_type参数的,一种是有的。

         我们先来看一下创建一个连接地址
t1=ConfigurationSettings.AppSettings["interface"];//支付接口,就是给的一个连接地址
            t2=ConfigurationSettings.AppSettings["account"];//支付宝帐户你的帐户
            t3=ConfigurationSettings.AppSettings["password"];//安全校验码,设置的商家验证码
            t4="images/logo_zfbsmall.gif";//按钮图片地址
            t5="test";//悬停说明
            cmd="0001";//默认
            subject="item";//商品名称
            body="decrip";//描述
            order_no=;//定单号,用户自己生成,方便自己管理                prices=100;//价格0.01~50000.00
            rurl="http://www.xxx.com/";//商品展示网址
            types="1";//1:商品购买2:服务购买3:网络拍卖4:捐赠
            number="1";//购买数量
            transport="3";//1:平邮2:快递3:虚拟物品
            ordinary_fee="";//平邮运费
            express_fee="";//快递运费
            readonlys="true";//交易信息是否只读
            buyer_msg="";//买家给卖家的留言
            buyer="";//买家Email
            buyer_name="";//买家姓名
            buyer_address="";//买家地址
            buyer_zipcode="";//买家邮编
            buyer_tel="";//买家电话号码
            buyer_mobile="";//买家手机号码
            partner=ConfigurationSettings.AppSettings["partenid"];//合作伙伴ID,这个是固定的
上面就是要提供得基本信息,然后就是生成支付宝得连接,也就是给支付宝提供一条带验证的购买信息。
public string creatAlipayItemURL(string t1,string t2,string t3,string t4,string t5,string cmd,string subject,string body,string order_no,string prices,string rurl,string types,string number,string transport,string ordinary_fee,string express_fee,string readonlys,string buyer_msg,string buyer,string buyer_name,string buyer_address,string buyer_zipcode,string buyer_tel,string buyer_mobile,string partner)
        {
            string itemURL,str2CreateAc,acCode;
            string INTERFACE_URL,sellerEmail,keyCode,imgsrc,imgtitle,AlipayItemURL;
            //初始化各必要变量
            INTERFACE_URL=t1+t2;//支付接口
            sellerEmail=t2;//商户支付宝账户(改成你自己的)
            keyCode=t3;//安全校验码(改成你自己的)
            imgsrc=t4;//支付宝按钮图片
            imgtitle=t5;//按钮悬停说明

            str2CreateAc="cmd" + cmd + "subject" + subject;
            str2CreateAc=str2CreateAc + "body" + body;
            str2CreateAc=str2CreateAc + "order_no" + order_no;
            str2CreateAc=str2CreateAc + "price" + prices;
            //str2CreateAc=str2CreateAc + "url" + rurl;
            str2CreateAc=str2CreateAc + "type" + types;
            str2CreateAc=str2CreateAc + "number" + number;
            str2CreateAc=str2CreateAc + "transport" + transport;
            /*str2CreateAc=str2CreateAc + "ordinary_fee" + ordinary_fee;
            str2CreateAc=str2CreateAc + "express_fee" + express_fee;
            str2CreateAc=str2CreateAc + "readonly" + readonlys;
            str2CreateAc=str2CreateAc + "buyer_msg" + buyer_msg;*/
            str2CreateAc=str2CreateAc + "seller" + sellerEmail;
            /*str2CreateAc=str2CreateAc + "buyer" + buyer;
            str2CreateAc=str2CreateAc + "buyer_name" + buyer_name;
            str2CreateAc=str2CreateAc + "buyer_address" + buyer_address;
            str2CreateAc=str2CreateAc + "buyer_zipcode" + buyer_zipcode;
            str2CreateAc=str2CreateAc + "buyer_tel" + buyer_tel;
            str2CreateAc=str2CreateAc + "buyer_mobile" + buyer_mobile;*/
            str2CreateAc=str2CreateAc + "partner" + partner;
            str2CreateAc=str2CreateAc + keyCode;

            //acCode=FormsAuthentication.HashPasswordForStoringInConfigFile(str2CreateAc,"MD5");
            acCode=this.GetMD5(str2CreateAc,"gb2312");
            itemURL=INTERFACE_URL + "?cmd=" + cmd;
            itemURL=itemURL + "&subject=" + HttpUtility.UrlEncode(subject);
            itemURL=itemURL + "&body=" + HttpUtility.UrlEncode(body);
            itemURL=itemURL + "&order_no=" + order_no;
            itemURL=itemURL + "&price=" + prices;
            //itemURL=itemURL + "&url=" + rurl;
            itemURL=itemURL + "&type=" + types;
            itemURL=itemURL + "&number=" + number;
            itemURL=itemURL + "&transport=" + transport;
            /*itemURL=itemURL + "&ordinary_fee=" + ordinary_fee;
            itemURL=itemURL + "&express_fee=" + express_fee;
            itemURL=itemURL + "&readonly=" + readonlys;
            itemURL=itemURL + "&buyer_msg=" + HttpUtility.UrlEncode(buyer_msg);
            itemURL=itemURL + "&buyer=" + HttpUtility.UrlEncode(buyer);
            itemURL=itemURL + "&buyer_name=" + HttpUtility.UrlEncode(buyer_name);
            itemURL=itemURL + "&buyer_address=" + HttpUtility.UrlEncode(buyer_address);
            itemURL=itemURL + "&buyer_zipcode=" + buyer_zipcode;
            itemURL=itemURL + "&buyer_tel=" + buyer_tel;
            itemURL=itemURL + "&buyer_mobile=" + buyer_mobile;*/
            itemURL=itemURL + "&partner=" + partner;
            itemURL=itemURL + "&ac=" + acCode;
            AlipayItemURL=itemURL;
                        return AlipayItemURL;
        }
这个函数就是返回生成的地址,里面注释掉的看你自己需要可以添加进去,然后就是md5码的问题,现在用默认的md5生成程序对中文的支持只限于GB2312,而支付宝使用的是GBK,虽然两个编码的内容GBK兼容GB2312但是毕竟两个编码方式不同,所以会产生错误,如果用英文或者数字不会有问题。上面下载里面带的一个md5.asp的算法支持中文。
        现在已经可以跳转到支付宝的页面了,而我们这边就要自己记录用户的信息已经生成的定单编号,这样在支付宝返回信息的时候来查询。在设定了返回地址后,我们就要看接收页面了。
string msg_id,order_no,gross,buyer_email,buyer_name,buyer_address,buyer_zipcode,buyer_tel,buyer_mobile,action,s_date,ac,notify_type;
    
            string returnTxt;//返回给支付宝通知接口的结果
            string alipayNotifyURL;//支付宝查询接口URL
            string myalipayEmail;//商户的支付宝Email
            string ResponseTxt="";
    

            returnTxt            = "N";
            alipayNotifyURL        = ConfigurationSettings.AppSettings["interfaceback"];//支付宝查询接口地址
            myalipayEmail        = ConfigurationSettings.AppSettings["account"];//填写您的支付宝帐号

    
            //检查支付宝通知接口传递过来的参数是否合法
            msg_id            = newop.DelStr(Request["msg_id"]);
            order_no        = newop.DelStr(Request["order_no"]);
            gross            = newop.DelStr(Request["gross"]);
            buyer_email        = newop.DelStr(Request["buyer_email"]);
            buyer_name        = newop.DelStr(Request["buyer_name"]);
            buyer_address    = newop.DelStr(Request["buyer_address"]);
            buyer_zipcode    = newop.DelStr(Request["buyer_zipcode"]);
            buyer_tel        = newop.DelStr(Request["buyer_tel"]);
            buyer_mobile    = newop.DelStr(Request["buyer_mobile"]);
            action            = newop.DelStr(Request["action"]);
            s_date            = newop.DelStr(Request["date"]);
            ac                = newop.DelStr(Request["ac"]);
            notify_type     = newop.DelStr(Request["notify_type"]);

            alipayNotifyURL    = alipayNotifyURL + "msg_id=" + msg_id + "&email=" + myalipayEmail + "&order_no=" + order_no;
    
            System.Net.WebClient isClient= new System.Net.WebClient();
            Stream isStream = isClient.OpenRead(alipayNotifyURL);
            StreamReader isReader = new StreamReader(isStream,System.Text.Encoding.GetEncoding("GB2312"));
            ResponseTxt = isReader.ReadToEnd();

if(action == "test")//测试商户网站URL是否正确安装
            {
                returnTxt    = "Y";
            }
            else if((action=="sendOff")&&(msg_id!=""))//发货通知
            {
                returnTxt        = "N";
                if((ResponseTxt == "true")||(ResponseTxt == "false"))
                {
                    //更新数据在商户系统里的订单数据;如果已经发货,则将returnTxt置为Y,否则为N
        
                }
                else
                {
                    //非法数据,不做更新
                    returnTxt="Error";
                }
            }
            else if((action=="sendOff")&&(notify_type=="web"))
            {
                //检查是否已经付帐,并记录            }
            else if((action=="checkOut")&&(msg_id!=""))//交易结束通知
            {
                returnTxt    = "Y";
                if((ResponseTxt=="true")||(ResponseTxt == "false"))
                {
                    //更新数据在商户系统里的订单数据;如果数据更新成功,则将returnTxt置为Y,否则为N
                    //更新数据
                    
//你的代码,更新你这边数据
                    returnTxt= "Y";
                }
                else
                {
                    //非法数据,不做更新
                    returnTxt    = "Error";
                }    
            }
            else
            {
                returnTxt="Error";
            }
            Response.Write(returnTxt);  

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

  智能语音控制技术在电力行业的广泛应用,是智能电网发展的必然趋势。在未来的物联网时代,“说出需求——得到反馈”的互动模式将进一步延伸,所有的电器

关键字: capsense express 赛普拉斯

苹果现在正在发布iOS 13的最终主要版本,而iOS 14将在今年晚些时候发布。 IOS 13.7更新包括Apple和Google针对iOS和Android发布的COVID-19暴露通知API的更新。 Exposure...

关键字: exposure express ios13.7 notifications

  中国,北京-2014年12月4日-为互联网基础设施提供高性能时钟解决方案的领导厂商Silicon Labs(芯科实验室有限公司,NASDAQ:SLAB)今天宣布推出PCI Express(P

关键字: express labs PCI Silicon si5311x

  首先说一下继承的好处:   1.提高了代码的复用性   2.让类和类之间产生了关系(关系是多态的前提)   将对像中的内容不断的向上抽取,就形成了关系,就有了继承,就

关键字: Android string

我们平时使用C++开发过程中或多或少都会使用std::string,但您了解string具体是如何实现的吗,这里程序喵给大家从源码角度分析一下。 读完本文相信您可以回答以下问题: ▼ string的常见的实现方式有几种?...

关键字: string 源码 C++

前言 今天在一个群里面看到的一个朋友提交,说of_property_read_string 这个函数有两个定义,到底是用了哪个呢? 所以这篇文章就说下这个函数。 函数引用的头文件 引用的头文件位置在 \kernel-4....

关键字: property string

字符串拼接是个常用的功能,经常性使用String做字符串拼接,当拼接次数多的时候,使用String方法会消耗大量的性能和时间,因为每次String拼接时都会建立一个新的对象,随着拼接次数的增多,性能消

关键字: java string

#include #include #include using namespace std; #define INFINITY 65535//无边时的权值 #define MAX_VERTE

关键字: string 算法

I know this is starting to look like a half-baked tutorial in assembly, but there's actually a reas

关键字: byte string

SDA协会去年发布了SD 7.0标准规范,引入PCIe,定义了全新的SD Express存储卡规格,现在Realtek(瑞昱)展示了第一款符合SD 7.0规范的主控制器“RTS5261”,相关产品也不

关键字: express realtek sd sd卡 主控 存储卡 瑞昱
关闭
关闭