#region 微信APP支付接口 /// /// 微信APP支付接口 /// /// 支付订单号支付金额 /// 1.安卓,2.IOS /// [HttpGet] public CommonResponse APP_Pay(string out_trade_no,Double total_fee,int type) { PayMent pm = new PayMent(); string ip = HttpContext.Current.Request.UserHostAddress; int money =int.Parse((total_fee * 100).ToString()); Wx_pay wp = pm.APP_PayMent("服务费",ip,money,out_trade_no,type); if (wp.sign == "") { return new CommonResponse { Data = null, Message = "系统异常,联系管理员!", Code = EnumResponseCode.Fail.GetHashCode() }; } return new CommonResponse { Data = wp, Message = String.Empty, Code = EnumResponseCode.Successful.GetHashCode() }; } #endregion /// ///是对返回数据类型 /// public class CommonResponse { public T Data { get; set; } /// /// 代码 1:失败,2:成功 /// public int Code { get; set; } /// /// 消息 /// public string Message { get; set; } /// /// 其他附带信息 /// public string Tag { get; set; } } /// /// 微信APP支付实体 /// public class Wx_pay { /// /// 应用ID /// public string appid { set; get; } = ""; /// /// 商户号 /// public string partnerid { set; get; } = ""; /// /// 预支付交易会话ID /// public string prepayid { set; get; } = ""; /// /// 扩展字段 /// public string package { set; get; } = "Sign=WXPay"; /// /// 随机字符串 /// public string noncestr { set; get; } = ""; /// /// 时间戳 /// public string timestamp { set; get; } = ""; /// /// 签名 /// public string sign { set; get; } = ""; } #region 微信APP支付 /// /// 微信APP支付 /// /// 商品描述 /// 商户号 /// 终端IP /// 金额 /// 商户订单号 /// public Wx_pay APP_PayMent( string boby, string spbill_create_ip, int total_fee, string out_trade_no,int type) { UnifiedOrder order = new UnifiedOrder(); if (type == 1) { order.appid = APP_Aconfig.appid; order.mch_id = APP_Aconfig.partnerid; } else { order.appid = APP_Iconfig.appid; order.mch_id = APP_Iconfig.partnerid; } order.attach = "APP名称-支付内容说明"; order.body = boby; order.device_info = "WEB"; order.nonce_str = TenpayUtil.getNoncestr(); order.notify_url = APP_Aconfig.url; order.out_trade_no = out_trade_no; order.trade_type = "APP"; order.spbill_create_ip = spbill_create_ip; order.total_fee = total_fee; TenpayUtil tenpay = new TenpayUtil(); string paySignKey = string.Empty; if (type == 1) { paySignKey = APP_Aconfig.paysignkey; } else { paySignKey = APP_Iconfig.paysignkey; } string prepay_id = tenpay.getPrepay_id(order, paySignKey); string timeStamp = TenpayUtil.getTimestamp(); string nonceStr = TenpayUtil.getNoncestr(); SortedDictionary sParams = new SortedDictionary(); sParams.Add("appid", order.appid); sParams.Add("partnerid", order.mch_id); sParams.Add("prepayid", prepay_id); sParams.Add("noncestr", nonceStr); sParams.Add("timestamp", timeStamp); sParams.Add("package", "Sign=WXPay"); string paySign = tenpay.getsign(sParams, paySignKey); Wx_pay wp = new Wx_pay(); wp.appid = order.appid; wp.partnerid = order.mch_id; wp.noncestr = nonceStr; wp.prepayid = prepay_id; wp.sign = paySign; wp.timestamp = timeStamp; return wp; } #endregion /// /// APP安卓支付配置 /// public class APP_Aconfig { public const string appid = "";//APPID public const string partnerid = "";//商户号 public const string paysignkey = "";//证书密匙 public const string url = "";//回调ur } /// /// APPios 支付配置 /// public class APP_Iconfig { public const string appid = "";//APPID public const string partnerid = "";//商户号 public const string paysignkey = "";//证书密匙 public const string url = "";//回调url } 对于 TenpayUtil tenpay = new TenpayUtil();这个类其他文章上有代码。 请求方式:http get 接口参数说明 名称 类型 必填 说明 out_trade_no string 是 支付订单ID total_fee Double 是 支付金额 type int 是 1.安卓,2.IOS 返回示例: /****失败示例**/ { "Code":1, /*状态码 1:失败 2:成功 */ "Message":"错误信息",/*消息(一般失败时,返回错误信息)*/ "Tag":""/*附加信息*/ } /****成功示例**/ { "Code":2, /*状态码 1:失败 2:成功*/ “Data”:[] "Message":"",/*消息(一般失败时,返回错误信息)*/ "Tag":"附加信息"/* */ } 接口返回Data集合参数说明 名称 类型 说明 appid string 应用ID partnerid String 商户号 prepayid String 预支付交易会话ID package String 扩展字段 noncestr String 随机字符串 timestamp String 时间戳 sign String 签名 本人还是个新手(刚入行不久),请多多关照,后续还有微信其他内容