123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace LYFZ.WxPayAPI
- {
-
-
-
-
- public class NativeNotify:Notify
- {
- public NativeNotify(Page page):base(page)
- {
- }
- public override void ProcessNotify()
- {
- WxPayData notifyData = GetNotifyData();
-
- if (!notifyData.IsSet("openid") || !notifyData.IsSet("product_id"))
- {
- WxPayData res = new WxPayData();
- res.SetValue("return_code", "FAIL");
- res.SetValue("return_msg", "回调数据异常");
- Log.Info(this.GetType().ToString(), "The data WeChat post is error : " + res.ToXml());
- page.Response.Write(res.ToXml());
- page.Response.End();
- }
-
- string openid = notifyData.GetValue("openid").ToString();
- string product_id = notifyData.GetValue("product_id").ToString();
- WxPayData unifiedOrderResult = new WxPayData();
- try
- {
- unifiedOrderResult = UnifiedOrder(openid, product_id);
- }
- catch
- {
- WxPayData res = new WxPayData();
- res.SetValue("return_code", "FAIL");
- res.SetValue("return_msg", "统一下单失败");
- Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml());
- page.Response.Write(res.ToXml());
- page.Response.End();
- }
-
- if (!unifiedOrderResult.IsSet("appid") || !unifiedOrderResult.IsSet("mch_id") || !unifiedOrderResult.IsSet("prepay_id"))
- {
- WxPayData res = new WxPayData();
- res.SetValue("return_code", "FAIL");
- res.SetValue("return_msg", "统一下单失败");
- Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml());
- page.Response.Write(res.ToXml());
- page.Response.End();
- }
-
- WxPayData data = new WxPayData();
- data.SetValue("return_code", "SUCCESS");
- data.SetValue("return_msg", "OK");
- data.SetValue("appid", WxPayConfig.APPID);
- data.SetValue("mch_id", WxPayConfig.MCHID);
- data.SetValue("nonce_str", WxPayApi.GenerateNonceStr());
- data.SetValue("prepay_id", unifiedOrderResult.GetValue("prepay_id"));
- data.SetValue("result_code", "SUCCESS");
- data.SetValue("err_code_des", "OK");
- data.SetValue("sign", data.MakeSign());
- Log.Info(this.GetType().ToString(), "UnifiedOrder success , send data to WeChat : " + data.ToXml());
- page.Response.Write(data.ToXml());
- page.Response.End();
- }
- private WxPayData UnifiedOrder(string openId,string productId)
- {
-
- WxPayData req = new WxPayData();
- req.SetValue("body", "test");
- req.SetValue("attach", "test");
- req.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());
- req.SetValue("total_fee", 1);
- req.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
- req.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
- req.SetValue("goods_tag", "test");
- req.SetValue("trade_type", "NATIVE");
- req.SetValue("openid", openId);
- req.SetValue("product_id", productId);
- WxPayData result = WxPayApi.UnifiedOrder(req);
- return result;
- }
- }
- }
|