string Pay(PayRequest req) { try { string result = string.Empty; #region 参数 Hashtable ht = new Hashtable(); ht.Add("appid", this.appid); ht.Add("timestamp", GetTimestamp().ToString()); ht.Add("once", req.once); ht.Add("attach", Base64Helper.Base64Encode(req.attach)); ht.Add("format", __format); ht.Add("method", __method); ht.Add("sign_type", __sign_type); //sign ht.Add("version", __version); ht.Add("data", req.data); ht.Add("key", this.secret_key); string sign = CreateSign(ht); ht.Add("sign", sign); #endregion #region 请求接口 string res = PostWebRequest(__request_url, CreateParams(ht), Encoding.UTF8); //string res = req.request_url+"?"+ CreateParams(ht); if (!string.IsNullOrEmpty(res)) { ResHaiBeiHu data = Newtonsoft.Json.JsonConvert.DeserializeObject <ResHaiBeiHu>(res); if (data != null) { ResHaiBeiHu_Result rere = Newtonsoft.Json.JsonConvert.DeserializeObject <ResHaiBeiHu_Result>(data.result); if (rere != null) { result = rere.payUrl; } } } #endregion return(result); } catch (Exception e) { throw (e); } }
string DoPay(PayRequestInfo info) { PayData pd = new PayData() { waresName = info.Name, cpOrderId = info.OrderNo, price = Convert.ToDecimal((info.Amount * 1.0 / 100).ToString("f2")), returnUrl = info.ReturnUrl, notifyUrl = this.notifyUrl, type = __pay_type }; PayRequest pr = new PayRequest() { once = Guid.NewGuid().ToString(), attach = info.Attach, data = Newtonsoft.Json.JsonConvert.SerializeObject(pd) }; return(Pay(pr)); }