当前位置: 首页 > 编程日记 > 正文

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

它现在这种支付方式比较多象网银在线等使用的方法都是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);

转载于:https://www.cnblogs.com/hzuIT/articles/751954.html

相关文章:

【Visual Studio 扩展工具】如何在ComponentOneFlexGrid树中显示RadioButton

概述 在ComponentOne Enterprise .NET控件集中,FlexGrid表格控件是用户使用频率最高的控件之一。它是一个功能强大的数据管理工具,轻盈且灵动,以分层的形式展示数据(数据呈现更加直观)。 FlexGrid 简介 FlexGrid 是业界…

如何 SQL Server 2005 实例之间传输登录和密码

INTRODUCTION 本文介绍如何不同服务器上的 Microsoft SQL Server 2005 实例之间传输登录和密码。 本文, 服务器 A 和服务器 B 是不同的服务器。 此外, 服务器 A 和 B 服务器都运行 SQL Server 2005。 将数据库从服务器 A 上的 SQLServer 实例移到 B, 服务器上的 SQLServer 实例…

IDEA配置GitHub报错GitHub Invalid authentication data.404 Not Found-Not Found

登录账户GitHub Invalid authentication data.404 Not Found-Not Found报错及解决办法1 登录自己的github账号--》头像---》settting2 Developer settings3 Personal access tokens4 回到IDEA中,粘贴上自己的token就可以了想要把自己的代码上传到GitHub中&#xff0…

console.log 简写

console.log 简写 平常代码调试总会用到console.log,但是每次写这么长也是很麻烦,就想着存一个简介一点的变量; 然后就随手写了下面代码; var a 10;var log console.log;log(a);调用的时候发现火狐浏览器报错了,仔细…

为何我的BLOG不能DIY?

今天想把MODULE调整一下,居然搞不定。估计是服务器又出问题了........不知道51CTO有没有备份我们的博克呀?

Java中的自动装箱和拆箱

自动装箱和拆箱自动装箱和拆箱自动装箱:拆箱1. 为什么要有包装类(或封装类)2. 基本数据类型与对应的包装类:3. 类型间的转换4. 何时发生自动装箱和拆箱赋值、数值运算时方法调用时:自动装箱、拆箱中的坑自动装箱和拆箱 目的&…

【Java】身份证号码验证

代码引用自:https://gitee.com/appleat/codes/ynrtqujv0wfgesm8ia9b547 1 package xxx;2 3 /**4 * Created by wdj on 2017/6/21.5 */6 7 import java.text.ParseException;8 import java.text.SimpleDateFormat;9 import java.util.Calendar;10 import java.util…

linux history记录格式修改

#保存一万条命令记录 sed -i s/^HISTSIZE1000/HISTSIZE10000/g /etc/profile#在/etc/profile的文件尾部添加如下行数配置信息 ######jiagu history xianshi######### USER_IPwho -u am i 2>/dev/null | awk {print $NF} | sed -e s/[()]//g if [ "$USER_IP" &quo…

从EAI到SOA

写在前面SOA现在越发闹腾的厉害了,各种宣传越来越多,都把SOA吹上天;到底SOA是什么,有啥神奇之处,真的想宣传说的那么好吗?看了种种文章,只是越发混沌。罢了,俺做技术的,商…

用C#实现FTP搜索引擎

晚辈最近用C#写了一个教育网FTP搜索引擎,希望能得到高手的指点。 网址:http://soso.ccnu.com.cn http://it.ccnu.edu.cn/soso 部分代码: using System;using softplib;using System.Threading;using System.Collections;using System.Ne…

IDEA配置GitHub和Gitee

IDEA配置GitHub和GiteeIDEA配置GitHub和GiteeGit准备IDEA内配置Git配置GitHub1. IDEA的Settings-->Version Control ---> GitHub2. 登录账户GitHub Invalid authentication data.404 Not Found-Not Found报错及解决办法2.1 登录自己的github账号--》头像---》settting2.2…

MATLAB 2014a (8.3) Compiler Runtime (MCR)

在安装的时候可以 ./install -H 界面化安装到自己目录下 MATLAB 2014a (8.3) Runtime Compiler (MCR) Errors when trying to launch deployed (using deploy tool) application in Ubuntu 13.04. Right after installation of MCR if one runs the deployed application follo…

[Quiz]竞赛题目 Word Trace

一、竞赛题目Problem Statement You are given a String[] grid representing a rectangular grid of letters. You are also given a String find, a word you are to find within the grid. The starting point may be anywhere in the grid. The path may move up, down, le…

c#总结最近的几项重要代码

java的代码就不说了,毕竟不是我的主业。 1.c#数据库连接池Hikari. (1)动态加载各类数据库驱动 (2)支持简单配置文件 (3)支持按照名称多数据库调用 (4)使用简洁 单数据库使用: Hikari…

动态模板列更新数据分页的例子

前台&#xff1a;<% Page language"c#" Codebehind"WebForm30.aspx.cs" AutoEventWireup"false" Inherits"csdn.WebForm30" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML>…

[您有新的未分配科技点]可,可,可持久化!?------0-1Trie和可持久化Trie普及版讲解...

这一次&#xff0c;我们来了解普通Trie树的变种&#xff1a;0-1Trie以及在其基础上产生的可持久化Trie&#xff08;其实&#xff0c;普通的Trie也可以可持久化&#xff0c;只是不太常见&#xff09; 先简单介绍一下0-1Trie&#xff1a;一个0-1Trie节点只有两个子节点&#xff0…

SQL查询1064报错 [ERR] 1064 - You have an error in your SQL syntax; check the manual.......

MySQL建表出现1064问题问题 SQL语句 DROP DATABASE IF EXISTS bookstore; DROP DATABASE bookstore; USE bookstore; CREATE TABLE t_user (id INT PRIMARY KEY auto_increment,username VARCHAR ( 20 ) NOT NULL UNIQUE,password VARCHAR ( 32 ) NOT NULL,email VARCHAR ( …

移动端丨-webkit-overflow-scrolling:touch属性导致页面卡住

起因 起因-webkit-overflow-scrolling问题解决方案&#xff1a; 方案一方案二思考为什么会出现这个问题总结故事的起因是&#xff0c;在一个多列表的页面上&#xff0c;页面在iOS11&#xff0c;跟iOS10中会发生页面卡住&#xff0c;不能进行滚动。 然后就怀疑是自己的样式写的出…

瑞星杀毒软件所有监控已禁用!

瑞星杀毒软件所有监控已禁用! 我的瑞星杀毒软件所有监控已禁用!在右下脚有个红色的小伞,可以升级,但是监控怎么都开启不了。 解决办法是&#xff1a;启动主程序&#xff0c;点“工具列表”&#xff0c;选择“瑞星监控中心”&#xff0c;点“运行”&#xff0c;在弹出的窗口…

Typora输出表情 Typora_Smile

文章目录小表情还挺好看的SmileNatureObjectsPlacesSymbols小表情还挺好看的 Smile &#x1f604; :smile:&#x1f606; :laughing:&#x1f60a; :blush:&#x1f603; :smiley:☺️ :relaxed:&#x1f60f; :smirk:&#x1f60d; :heart_eyes:&#x1f618; :kissing_hear…

COOKIE操作

import scrapyclass CookiedemoSpider(scrapy.Spider):name cookiedemo# allowed_domains [www.douban.com]start_urls [https://www.douban.com/accounts/login/]def parse(self, response):# 登录成功后对页面数据进行存储fp open("main.html", "w",…

01--安装Activiti流程设计器eclipse插件

Activiti1 安装流程设计器eclipse插件   Name:Activiti BPMN 2.0 designer&#xff08;随便起个名字&#xff09;   Location: http://activiti.org/designer/update/ 安装完成后勾选(不勾选不生成bpmn文件) 转载于:https://www.cnblogs.com/miye/p/7283468.html

许美静《盖被》

空白时光有你来填满可以是平静或灿烂有时浓有时淡心胸要宽广才能够经得起波浪在旅途中风起和云涌每个人都会有起落有时浮有时沉有时没方向有时在雾里向前闯一生中难免常会有不如意道路太平坦会失去了勇气就(让)算天塌下来把它当被盖我只想好好过现在日子太贫乏会失去了意义万里…

SBO顾问的收入

SAP顾问的收入&#xff0c;在很多文章都有专门记载了&#xff0c;有些人比我更熟悉。差别也是比较大&#xff0c;在我熟悉的行业SAP business one产品中&#xff0c;我给大家说说我所知道的sbo顾问的收入&#xff0c;给希望入这个行业的人或感兴趣的人一点小小的提示。总体来说…

带无线网卡的电脑开启热点

带无线网卡的电脑开启热点 文章目录带无线网卡的电脑开启热点准备&#xff1a;共享WiFi的建立建立Bat批处理文件准备&#xff1a; 无线网卡 大部分笔记本自带或USB无线网卡 验证你的无线网卡是否支持承载网络 按winR调出命令行&#xff0c;输入命令netsh wlan show drivers在…

BZOJ2275[Coci2010]HRPA——斐波那契博弈

题目描述 N个石子&#xff0c;A和B轮流取&#xff0c;A先。每个人每次最少取一个&#xff0c;最多不超过上一个人的个数的2倍。取到最后一个石子的人胜出&#xff0c;如果A要有必胜策略&#xff0c;第一次他至少要取多少个。 输入 第一行给出数字N&#xff0c;N<10^15.第二行…

MonoRail学习笔记一:一个小例子

随着微软放出消息&#xff0c;准备发布MVC的框架&#xff0c;各种议论纷至沓来。以前用java、jsp对它的MVC结构、集中控制印象特别深刻&#xff0c;自从用了.NET后&#xff0c;虽然webform的控件很好用&#xff0c;总感觉有点怪怪的在网上搜了一下&#xff0c;发现早就有了Mono…

一个总裁做企业的十条心得

经常面对很多企业老总&#xff0c;但能够促膝谈心的不多&#xff0c;原因是大家忙&#xff0c;忙得没时间想一些事情。在我采访的一个老总中&#xff0c;他给了我十句话&#xff0c;我铭刻在心&#xff0c;兹整理出来&#xff0c;共同分享。鉴于不便透露姓名&#xff0c;希望有…

BZOJ1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列

n<100000个数表示每头牛在K<30种物品的选取情况&#xff0c;该数在二进制下某位为0表示不选1表示选&#xff0c;求一个最大的区间使区间内选择每种物品的牛一样多。 数学转化&#xff0c;把不同状态间单变量的关系通过不等式移项转变为单状态的多变量关系。 sum[i,j]表示…

AttributeError: Cant get attribute SPPF on module models

运行YOLOV5出现报错AttributeError: Cant get attribute SPPF 问题 AttributeError: Cant get attribute SPPF 运行yolov5下面Tags5的代码出现问题&#xff1a; AttributeError: Cant get attribute SPPF on module models 搞了很久&#xff0c;最终得到解决方案&#xff0…