支付宝Payto接口用c#.net实现的代码

时间:2007-10-15 12:03:30   来源:网络博客  作者:  编辑:gaopoadmin


        现在已经可以跳转到支付宝的页面了,而我们这边就要自己记录用户的信息已经生成的定单编号,这样在支付宝返回信息的时候来查询。在设定了返回地址后,我们就要看接收页面了。

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


关键字:支付宝,Payto,接口,用c#.net,实现,代码

相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面