MicroPayData.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Dynamic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace LYFZ.WxPayAPI
  7. {
  8. public class MicroPayData
  9. {
  10. /// <summary>
  11. /// 微信解析后数据集合
  12. /// </summary>
  13. /// <param name="body"></param>
  14. /// <param name="total_fee"></param>
  15. /// <param name="auth_code"></param>
  16. /// <param name="AppId"></param>
  17. /// <param name="MacId"></param>
  18. /// <param name="key"></param>
  19. /// <param name="sub_mch_id"></param>
  20. /// <returns></returns>
  21. public dynamic PosWeiXinData(string body, string total_fee, string auth_code, string AppId = "", string MacId = "", string key = "", string sub_mch_id = "")
  22. {
  23. WxPayData data = new WxPayData();
  24. data.SetValue("auth_code", auth_code);//授权码
  25. data.SetValue("body", body);//商品描述
  26. data.SetValue("total_fee", int.Parse(total_fee));//总金额
  27. data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());//产生随机的商户订单号
  28. data.SetValue("sub_mch_id", sub_mch_id);//绑定子商户号
  29. data.SetValue("spbill_create_ip", WxPayConfig.IP);//终端ip
  30. data.SetValue("appid", AppId);//公众账号ID
  31. data.SetValue("mch_id", MacId);//商户号
  32. data.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));//随机字符串
  33. data.SetValue("sign", data.MakeSign(key));//签名
  34. string xml = data.ToXml();
  35. dynamic dyData = new ExpandoObject();
  36. dyData.Url = "https://api.mch.weixin.qq.com/pay/micropay";
  37. dyData.PostData = xml;
  38. return (dyData);
  39. }
  40. }
  41. }