代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
接收支付宝信息并进行相应操作
作者:
dezai
/ 发布于
2014/6/20
/
596
<%@ Page Language="C#" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.Text" %> <%@ Import Namespace="System.Security.Cryptography" %> <script type="text/C#" runat="server"> private string returnTxt = "N"; //返回给支付宝通知接口的结果 private string alipayNotifyURL = "http://notify.alipay.com/trade/notify_query.do?"; //支付宝查询接口URL private string myalipayEmail = "341081@qq.com"; //商户的支付宝Email private string constPaySecurityCode = ""; //码 private SqlConnection conn = new SqlConnection(); private string GetMD5(string s) { System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] t = md5.ComputeHash(System.Text.Encoding.GetEncoding("gb2312").GetBytes(s)); StringBuilder sb = new StringBuilder(32); for (int i = 0; i < t.Length; i++) { sb.Append(t[i].ToString("x").PadLeft(2, "0")); } return sb.ToString(); } private String Get_Http(String a_strUrl, int timeout) { string strResult; try { System.Net.HttpWebRequest myReq = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create(a_strUrl); myReq.Timeout = timeout; System.Net.HttpWebResponse HttpWResp = (System.Net.HttpWebResponse) myReq.GetResponse(); Stream myStream = HttpWResp.GetResponseStream(); StreamReader sr = new StreamReader(myStream, System.Text.Encoding.Default); System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(); while (-1 != sr.Peek()) { strBuilder.Append(sr.ReadLine() + "\r\n"); } strResult = strBuilder.ToString(); } catch (Exception exp) { strResult = "错误:" + exp.Message; } return strResult; } public void send(string sql) { string dbconn = "data source=127.0.0.1;UID=Cm;PWD=fallenangel;database=text"; conn = new SqlConnection(dbconn); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); int aa = cmd.ExecuteNonQuery(); conn.Close(); } private void Page_Load(object sender, System.EventArgs e) { //检查支付宝通知接口传递过来的参数是否合法 string msg_id = System.Web.HttpContext.Current.Request["msg_id"]; string order_no = System.Web.HttpContext.Current.Request["order_no"]; string gross = System.Web.HttpContext.Current.Request["gross"]; string buyer_email = System.Web.HttpContext.Current.Request["buyer_email"]; string buyer_name = System.Web.HttpContext.Current.Request["buyer_name"]; string buyer_address = System.Web.HttpContext.Current.Request["buyer_address"]; string buyer_zipcode = System.Web.HttpContext.Current.Request["buyer_zipcode"]; string buyer_tel = System.Web.HttpContext.Current.Request["buyer_tel"]; string buyer_mobile = System.Web.HttpContext.Current.Request["buyer_mobile"]; string action = System.Web.HttpContext.Current.Request["action"]; string s_date = System.Web.HttpContext.Current.Request["date"]; string ac = System.Web.HttpContext.Current.Request["ac"]; string notify_type = System.Web.HttpContext.Current.Request["notify_type"]; alipayNotifyURL = alipayNotifyURL + "msg_id=" + msg_id + "&email=" + myalipayEmail + "&order_no=" + order_no; //获取支付宝ATN返回结果,true和false都是正确的订单信息,invalid 是无效的 string responseTxt = Get_Http(alipayNotifyURL, 120000); string Str = "msg_id" + msg_id + "order_no" + order_no + "gross" + gross + "buyer_email" + buyer_email + "buyer_name" + buyer_name + "buyer_address" + buyer_address + "buyer_zipcode" + buyer_zipcode + "buyer_tel" + buyer_tel + "buyer_mobile" + buyer_mobile + "action" + action + "date" + s_date + constPaySecurityCode; string ac_code = GetMD5(Str); if (action == "test") //支付宝接口测试是否有效 { returnTxt = "Y"; } if (action == "sendOff") //发货通知 { if (responseTxt.Substring(0, 4) == "true" || responseTxt.Substring(0, 4) == "fals")//ATN,验证消息是否支付宝发过来 { if (ac_code == ac)//验证消息是否被修改 { //数据库操作 } } } if (action == "checkOut") //交易完成通知 { returnTxt = "N"; if (responseTxt.Substring(0, 4) == "true" || responseTxt.Substring(0, 4) == "fals")//ATN,验证消息是否支付宝发过来 { if (ac_code == ac)//验证消息是否被修改 { //数据库操作 } } } System.Web.HttpContext.Current.Response.Write(returnTxt); } </script>
试试其它关键字
支付宝
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
dezai
贡献的其它代码
(
1065
)
.
双色球
.
列出所有物理网络适配器
.
快乐数的 Python 实现
.
计算当月还剩天数
.
猜属相
.
二十四小时时钟
.
每日一语
.
很酷的日历
.
超长日历表单
.
最简单的时钟
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3