123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- using Aop.Api.Util;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Web;
- namespace EMIS.Utility.OnlinePay.Alipay.Models
- {
- public class Notify
- {
- #region 字段
- private string _partner = "";
- private string _charset = "";
- private string _sign_type = "";
- private string _alipay_public_key = "";
-
- private string Https_veryfy_url = "";
- #endregion
-
-
-
-
-
-
- public Notify(string charset, string sign_type, string pid, string mapiUrl, string alipay_public_key)
- {
-
- _charset = charset;
- _sign_type = sign_type;
- _partner = pid;
- Https_veryfy_url = mapiUrl + "?service=notify_verify&";
- _alipay_public_key = alipay_public_key;
- }
-
-
-
-
-
-
-
- public bool Verify(SortedDictionary<string, string> inputPara, string notify_id, string sign)
- {
-
- bool isSign = GetSignVeryfy(inputPara, sign);
-
-
-
-
-
-
-
-
-
- if (isSign)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
-
-
-
- private string GetPreSignStr(SortedDictionary<string, string> inputPara)
- {
- Dictionary<string, string> sPara = new Dictionary<string, string>();
-
- sPara = Core.FilterPara(inputPara);
-
- string preSignStr = Core.CreateLinkString(sPara);
- return preSignStr;
- }
-
-
-
-
-
-
- private bool GetSignVeryfy(SortedDictionary<string, string> inputPara, string sign)
- {
- Dictionary<string, string> sPara = new Dictionary<string, string>();
-
- sPara = Core.FilterPara(inputPara);
-
- string preSignStr = Core.CreateLinkString(sPara);
-
- bool isSign = false;
- if (sign != null && sign != "")
- {
- switch (_sign_type)
- {
- case "RSA":
- isSign = AlipaySignature.RSACheckContent(preSignStr, sign, _alipay_public_key, _charset, _sign_type, false);
- break;
- case "RSA2":
- isSign = AlipaySignature.RSACheckContent(preSignStr, sign, _alipay_public_key, _charset, _sign_type, false);
- break;
- default:
- break;
- }
- }
- return isSign;
- }
-
-
-
-
-
- private string GetResponseTxt(string notify_id)
- {
- string veryfy_url = Https_veryfy_url + "partner=" + _partner + "¬ify_id=" + notify_id;
-
- string responseTxt = Get_Http(veryfy_url, 120000);
- return responseTxt;
- }
-
-
-
-
-
-
- private string Get_Http(string strUrl, int timeout)
- {
- string strResult;
- try
- {
- HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl);
- myReq.Timeout = timeout;
- HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
- Stream myStream = HttpWResp.GetResponseStream();
- StreamReader sr = new StreamReader(myStream, Encoding.Default);
- StringBuilder strBuilder = new StringBuilder();
- while (-1 != sr.Peek())
- {
- strBuilder.Append(sr.ReadLine());
- }
- strResult = strBuilder.ToString();
- }
- catch (Exception exp)
- {
- strResult = "错误:" + exp.Message;
- }
- return strResult;
- }
- }
- }
|