public RequestResultDto PayNotify(string msgBody) { RequestResultDto requestResult = new RequestResultDto { Ret = 0, Msg = "Ok" }; Dictionary <string, string> dict = new Dictionary <string, string> { { "return_code", "SUCCESS" }, { "return_msg", "Ok" } }; try { PayNotifyInfo pnInfo = XmlHelper.XmlToEntity <PayNotifyInfo>(msgBody); _log.Add(new Log() { Msg = "return_code:" + pnInfo.return_code + ",return_msg:" + pnInfo.return_msg + ",pnInfo.out_trade_no:" + pnInfo.out_trade_no + ",pnInfo.total_fee:" + pnInfo.total_fee, Ret = 168, CreateTime = DateTime.Now }); if (pnInfo != null && pnInfo.return_code == "SUCCESS" && pnInfo.result_code == "SUCCESS") { #region 做自己的业务 if (pnInfo.appid == "") { string partnerKey = ""; if (!GetSignAndCheckSign(msgBody, partnerKey)) { dict["return_code"] = "FAIL"; dict["return_msg"] = "签名验证错误"; requestResult.Msg = Utils.ArrayToXml(dict); return(requestResult); } } #endregion } } catch (Exception ex) { _log.Add(new Log() { Msg = "error:" + ex.ToString(), Ret = 168, CreateTime = DateTime.Now }); dict["return_code"] = "FAIL"; dict["return_msg"] = "系统错误"; } requestResult.Msg = Utils.ArrayToXml(dict); return(requestResult); }
/// <summary> /// 发红包接口 /// </summary> /// <param name="reOpenId">接收红包的用户</param> /// <param name="totalamount">付款金额(分)</param> /// <param name="wishing"></param> /// <param name="actName"></param> /// <param name="remark"></param> /// <param name="result"></param> /// <returns></returns> public SendRedPackReturn SendRedPack(string reOpenId, string totalamount, string wishing, string actName, string remark, string sendName, string mchId, string partnerKey, string wxappId, string cert, out RequestResultDto result) { SendRedPackReturn srpReturn = null; result = new RequestResultDto { Ret = 0, Msg = "ok" }; try { string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; string orderNo = mchId + DateTime.Now.ToString("yyyyMMdd") + Utils.CreateNoncestr(10); //商户订单号 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); X509Certificate2 cer = new X509Certificate2(cert, mchId, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); webrequest.ClientCertificates.Add(cer); webrequest.Method = "post"; var dict = new Dictionary <string, string> { { "nonce_str", Utils.CreateNoncestr(16) }, { "mch_billno", orderNo }, { "mch_id", mchId }, { "wxappid", wxappId }, { "nick_name", sendName }, { "send_name", sendName }, { "re_openid", reOpenId }, { "total_amount", totalamount }, { "min_value", totalamount }, { "max_value", totalamount }, { "total_num", "1" }, { "wishing", wishing }, { "client_ip", Utils.GetIp() }, { "act_name", actName }, { "remark", remark }, }; dict.Add("sign", Signature(dict, partnerKey)); var postDataStr = Utils.ArrayToXml(dict); _log.Add(new Log() { Msg = postDataStr, Ret = 168, CreateTime = DateTime.Now }); byte[] postData = Encoding.UTF8.GetBytes(postDataStr); Stream reqStream = webrequest.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); reqStream.Close(); HttpWebResponse webreponse = (HttpWebResponse)webrequest.GetResponse(); Stream stream = webreponse.GetResponseStream(); string resp = string.Empty; using (StreamReader reader = new StreamReader(stream)) { resp = reader.ReadToEnd(); _log.Add(new Log() { Msg = resp, Ret = 168, CreateTime = DateTime.Now }); } srpReturn = XmlHelper.XmlToEntity <SendRedPackReturn>(resp); } catch (Exception exp) { result = new RequestResultDto { Ret = 10009, Msg = "出错," + exp.Message }; _log.Add(new Log() { Msg = exp.ToString(), Ret = 168, CreateTime = DateTime.Now }); } return(srpReturn); }
public void AddLog(Log model) { _log.Add(model); }