//微信 private string WxPay(string uid, decimal money) { UserFinancialManager ufm = new UserFinancialManager(); Hashtable hashuf = new Hashtable(); hashuf["ID"] = CommonHelper.GetGuid; hashuf["UserID"] = uid; hashuf["OrderNum"] = SiteHelper.GenerateOrderNum(); hashuf["OrderPayID"] = SiteHelper.GeneratePayID(); hashuf["ChangesAmount"] = money; hashuf["ChangesTime"] = SiteHelper.GetWebServerCurrentTime(); hashuf["ChangesType"] = (int)UserFinancialChangesType.Recharge; hashuf["Remark"] = "用户充值"; hashuf["Operator"] = uid; hashuf["OperatorType"] = (int)UserFinancialOperatorType.User; hashuf["OperatorWay"] = (int)UserFinancialOperatorWay.WeixinPubPay; hashuf["State"] = (int)UserFinancialState.NewSubmit; bool isSuccess = ufm.AddOrEditUserFinancialInfo(hashuf, null); if (isSuccess) { Hashtable uf = ufm.GetUserFinancialPayInfoByPayID(hashuf["OrderPayID"].ToString()); if (uf == null) { return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败")); } else { WxUtil wxUtil = new WxUtil(); string prepayid = "", sign = ""; prepayid = wxUtil.GetPrepayId(hashuf["OrderPayID"].ToString(), "余额充值", money, weixinNotifyUrl, ip, openID); Hashtable result = new Hashtable(); result["PayWay"] = payway; result["appId"] = WxConfig.AppId; result["timeStamp"] = wxUtil.genTimeStamp(); result["nonceStr"] = wxUtil.genNonceStr(); result["package"] = "prepay_id=" + prepayid; result["signType"] = "MD5"; SortedDictionary <string, string> dic = new SortedDictionary <string, string>(); dic.Add("appId", result["appId"].ToString()); dic.Add("timeStamp", result["timeStamp"].ToString()); dic.Add("nonceStr", result["nonceStr"].ToString()); dic.Add("package", result["package"].ToString()); dic.Add("signType", result["signType"].ToString()); sign = wxUtil.getSign(dic); result["sign"] = sign; Logger.Info("RechargePay,WxPay prepayId:" + result["prepayId"]); return(SiteHelper.GetJsonFromHashTable(result, "success", "生成支付订单成功", "RechargePay")); } } else { return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败")); } }
//微信 private string WxPay(string uid, decimal money) { UserFinancialManager ufm = new UserFinancialManager(); Hashtable hashuf = new Hashtable(); hashuf["ID"] = CommonHelper.GetGuid; hashuf["UserID"] = uid; hashuf["OrderNum"] = SiteHelper.GenerateOrderNum(); hashuf["OrderPayID"] = SiteHelper.GeneratePayID(); hashuf["ChangesAmount"] = money; hashuf["ChangesTime"] = SiteHelper.GetWebServerCurrentTime(); hashuf["ChangesType"] = (int)UserFinancialChangesType.Recharge; hashuf["Remark"] = "用户充值"; hashuf["Operator"] = uid; hashuf["OperatorType"] = (int)UserFinancialOperatorType.User; hashuf["OperatorWay"] = (int)UserFinancialOperatorWay.WeixinPay; hashuf["State"] = (int)UserFinancialState.NewSubmit; bool isSuccess = ufm.AddOrEditUserFinancialInfo(hashuf, null); if (isSuccess) { Hashtable uf = ufm.GetUserFinancialPayInfoByPayID(hashuf["OrderPayID"].ToString()); if (uf == null) { return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败")); } else { WxUtil wxUtil = new WxUtil(); string prepayid = "", sign = ""; prepayid = wxUtil.GetPrepayId(hashuf["OrderPayID"].ToString(), "余额充值", money, weixinNotifyUrl, HttpContext.Current.Request.UserHostAddress); Hashtable result = new Hashtable(); result["PayWay"] = payway; result["appId"] = pay.wxpay.WxConfig.AppId; result["partnerId"] = pay.wxpay.WxConfig.MchId; result["prepayId"] = prepayid; result["packageValue"] = "Sign=WXPay"; result["nonceStr"] = wxUtil.genNonceStr(); result["timeStamp"] = wxUtil.genTimeStamp(); SortedDictionary <string, string> dic = new SortedDictionary <string, string>(); dic.Add("appid", result["appId"].ToString()); dic.Add("noncestr", result["nonceStr"].ToString()); dic.Add("package", result["packageValue"].ToString()); dic.Add("partnerid", result["partnerId"].ToString()); dic.Add("prepayid", result["prepayId"].ToString()); dic.Add("timestamp", result["timeStamp"].ToString()); sign = wxUtil.getSign(dic); result["sign"] = sign; Logger.Info("RechargePay,WxPay prepayId:" + result["prepayId"]); ICache cache = CacheFactory.GetCache(); DateTime dt = DateTime.Now.AddSeconds(5); cache.Set(cacheKey, uid, dt - DateTime.Now); cache.Dispose(); return(SiteHelper.GetJsonFromHashTable(result, "success", "生成支付订单成功", "RechargePay")); } } else { return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败")); } }