由于微信在校验参数时采用了“微信服务端”校验,它的参数是前期定义好的,所以用户不能自己添加自定义的参数,你可以把参数写在Attach字段时,作为它的附加参数。
参数和返回值定义如下:
public class NotifyResult : ResultBase { public NotifyResult(ResultBuilder resultBuilder) : base(resultBuilder) { } /// <summary> /// 设备号 /// </summary> public string Device_Info { get { return GetValue("device_info"); } } /// <summary> /// 用户标识 /// </summary> public string OpenId { get { return GetValue("openid"); } } /// <summary> /// 是否关注公众号 /// </summary> public bool Is_Subscribe { get { return GetBooleanValue("is_subscribe"); } } /// <summary> /// 交易类型 /// </summary> public TradeType Trade_Type { get { return (TradeType)GetEnumValue<TradeType>("trade_type"); } } /// <summary> /// 付款银行 /// </summary> public string Bank_Type { get { return GetValue("bank_type"); } } /// <summary> /// 总金额 /// </summary> public int Total_Fee { get { return GetIntValue("total_fee"); } } /// <summary> /// 现金券金额 /// </summary> public int Coupon_Fee { get { return GetIntValue("coupon_fee"); } } /// <summary> /// 货币种类 货币类型,符合 ISO 4217标准的三位字母代码,默认人民币:CNY /// </summary> public string Fee_Type { get { return GetValue("fee_type"); } } /// <summary> /// 微信支付订单号 /// </summary> public string Transaction_Id { get { return GetValue("transaction_id"); } } /// <summary> /// 商户订单号 /// </summary> public string Out_Trade_No { get { return GetValue("out_trade_no"); } } /// <summary> /// 商家数据包 /// </summary> public string Attach { get { return GetValue("attach"); } } /// <summary> /// 支付完成时间 /// </summary> public string Time_End { get { return GetValue("time_end"); } } /// <summary> /// 产品ID /// </summary> public string Product_Id { get { return GetValue("product_id"); } } }
基本这些已经够用了,如果你的业务需要其它信息(发到微信再发回来),直接写到Attach里即可。
统一的回调封装
下面代码是大叔Lind框架对微信模块的封装,体现了自定义参数的作用
/// <summary> /// 微信回调 /// </summary> public string WeixinNotify() { Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info("微信Callback"); WxPaymentConfig wxPaymentConfig = new WxPaymentConfig(); WxPayImpl wxPayImpl = new WxPayImpl(wxPaymentConfig); string Msg = wxPayImpl.RecieveWxPayNotify((notify) => { int projectId; int.TryParse(notify.Attach, out projectId); string fullName = Db.Project_Modules.Where(i => i.Id == projectId).FirstOrDefault().FullName; taskInfoProvider = Lind.DDD.Plugins.PluginManager.Resolve<ITaskInfoProvider>(fullName); taskInfoProvider.Pay_Callback(new PayCallbackParams { OrderId = notify.Out_Trade_No, TradeId = notify.Transaction_Id }); }, (msg) => { }); return Msg; }