/// <summary> /// 企业付款到零钱包 /// </summary> /// <param name="inputObj"></param> /// <param name="AdminHotelid"></param> /// <param name="url"></param> /// <param name="timeOut"></param> /// <returns></returns> private static WxPayData Refunds(WxPayData inputObj, string AdminHotelid, string url, int Hotelid = 0, int timeOut = 6) { inputObj.SetValue("mch_appid", WxPayConfig.APPID(AdminHotelid, Hotelid)); //商户账号appid inputObj.SetValue("mchid", WxPayConfig.MCHID(AdminHotelid, Hotelid)); //商户号 inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串 inputObj.SetValue("partner_trade_no", WxPayApi.GenerateOutTradeNo(AdminHotelid, Hotelid)); //商户订单号 inputObj.SetValue("sign", inputObj.MakeSignOwn(AdminHotelid, Hotelid)); //签名 string xml = inputObj.ToXml(); var start = DateTime.Now; string response = HttpService.PostOwn(xml, url, true, timeOut, AdminHotelid, Hotelid);//调用HTTP通信接口提交数据到API Log.Debug("企业付款到零钱包response:", response); var end = DateTime.Now; int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时 //将xml格式的结果转换为对象以返回 WxPayData result = new WxPayData(); result.FromXml(response); return(result); }
public ContentResult isSign(string openid = "o2xvw0DbxcG8dI9U2p7HAy-GUJLk") { var bus = new Bus(this.DataSource); string result = bus.isSign(openid, WxPayConfig.APPID("乐清市"), "乐清市").ToString(); return(Content(result)); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["code"] != null) { string state = ""; if (Request["state"] != null) { state = Server.UrlDecode(Request["state"]); } string code = Request["code"].ToString(); string postUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code"; postUrl = string.Format(postUrl, WxPayConfig.APPID("1", 0), WxPayConfig.APPSECRET("1", 0), code); string returnJason = GetJson(postUrl); //获取返回信息 JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> json = (Dictionary <string, object>)serializer.DeserializeObject(returnJason); object value; string openid = ""; if (json.TryGetValue("openid", out value)) { openid = value.ToString(); Session["zdyopenid"] = openid.ToString(); Session.Timeout = 60 * 60 * 24; } Log.Info("获取智订云openid:" + openid + ",URL:", state); Response.Redirect(state, false); } }
private static WxPayData Refund(WxPayData inputObj, string AdminHotelid, int Hotelid = 0, int timeOut = 6) { string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; inputObj.SetValue("mch_billno", WxPayApi.GenerateOutTradeNo(AdminHotelid, Hotelid)); //商户订单号 inputObj.SetValue("wxappid", WxPayConfig.APPID(AdminHotelid, Hotelid)); //公众账号ID inputObj.SetValue("mch_id", WxPayConfig.MCHID(AdminHotelid, Hotelid)); //商户号 inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串 inputObj.SetValue("sign", inputObj.MakeSign(AdminHotelid, Hotelid)); //签名 string xml = inputObj.ToXml(); var start = DateTime.Now; Log.Debug("WxPayApi", "Refund request : " + xml); string response = HttpService.Post(xml, url, true, timeOut, AdminHotelid, Hotelid);//调用HTTP通信接口提交数据到API Log.Debug("WxPayApi", "Refund response : " + response); var end = DateTime.Now; int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时 //将xml格式的结果转换为对象以返回 WxPayData result = new WxPayData(); result.FromXml(response); return(result); }
/// <summary> /// 实名验证(1分钱) /// </summary> /// <param name="openid"></param> /// <param name="realname"></param> /// <param name="cardid"></param> /// <returns></returns> public JsonResult CheckRealName(string openid, string nickname, string realname, string cardid, string city) { city = "杭州市"; var bus = new Bus(this.DataSource); var isSign = bus.isSign(openid, WxPayConfig.APPID(city), city); var user = bus.GetUserInfo(openid, WxPayConfig.APPID(city)); nickname = (string.IsNullOrEmpty(nickname)) ? "" : nickname; var exdata = bus.Sign(openid, nickname, Request.UserHostAddress, city); var pay = new NativePay(); var paydata = pay.GetPay(openid, realname, cardid, city); if (user != null) { user.DataDriver = this.DataSource; user.Realname = realname; user.Creid = cardid; user.RNameChecked = 0; user.out_trade_no = paydata.GetValue("out_trade_no").ToString(); user.RCheckTime = DateTime.Now; user.Store(); } string timeStamp = paydata.IsSet("timeStamp")? paydata.GetValue("timeStamp").ToString():""; string nonceStr = paydata.IsSet("nonceStr") ? paydata.GetValue("nonceStr").ToString() : ""; string package = paydata.IsSet("package") ? paydata.GetValue("package").ToString() : ""; string signType = paydata.IsSet("signType") ? paydata.GetValue("signType").ToString() : ""; string paySign = paydata.IsSet("paySign") ? paydata.GetValue("paySign").ToString() : ""; return(Json(new { exdata = exdata, isSign = isSign, timeStamp = timeStamp, nonceStr = nonceStr, package = package, signType = signType, paySign = paySign, realname = realname }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 生成二维码 /// </summary> /// <param name="code"></param> /// <returns></returns> public JsonResult MadeCode(string openid, string city) { string qrcode = string.Empty, sign = string.Empty, first = string.Empty, TimeStamp = string.Empty; var bus = new Bus(this.DataSource); bool isSign = bus.isSign(openid, WxPayConfig.APPID(city), city); var wxpay = new WxPayApi(); var list = new List <string>(); string citycode = WxPayConfig.getCityCode(city);//"YQ0001"; if (isSign) { //var user = bus.GetEntrustinfo(openid, WxPayConfig.APPID); qrcode = "gowechat://" + openid + "#" + WxPayConfig.APPID(city) + "#" + citycode + "#" + WxPayApi.GenerateTimeStamp(1); sign = bus.toSign(qrcode); first = qrcode + "#" + sign; int offlinelimits = Convert.ToInt16(ConfigurationManager.AppSettings["offlinelimits"]); for (int i = 1; i < offlinelimits + 1; i++) { TimeStamp = WxPayApi.GenerateTimeStamp(i + 1); qrcode = "gowechat://" + openid + "#" + WxPayConfig.APPID(city) + "#" + citycode + "#" + TimeStamp; sign = bus.toSign(qrcode); list.Add(citycode + "#" + TimeStamp + "#" + sign);//2017-8-17作了调整 } } return(Json(new { mxqrcode = first, items = list, openid = openid, appid = WxPayConfig.APPID(city) }, JsonRequestBehavior.AllowGet)); }
/** * * 网页授权获取用户基本信息的全部过程 * 详情请参看网页授权获取用户基本信息:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html * 第一步:利用url跳转获取code * 第二步:利用code去获取openid和access_token * */ public void GetOpenidAndAccessToken(string AdminHotelid, int Hotelid = 0) { if (!string.IsNullOrEmpty(page.Request.QueryString["code"])) { //获取code码,以获取openid和access_token string code = page.Request.QueryString["code"]; Log.Info(this.GetType().ToString(), "Get code : " + code); GetOpenidAndAccessTokenFromCode(code, AdminHotelid, Hotelid); } else { //构造网页授权获取code的URL string host = page.Request.Url.Host; string path = page.Request.Path; string redirect_uri = HttpUtility.UrlEncode("http://" + host + path); WxPayData data = new WxPayData(); data.SetValue("appid", WxPayConfig.APPID(AdminHotelid, Hotelid)); data.SetValue("redirect_uri", redirect_uri); data.SetValue("response_type", "code"); data.SetValue("scope", "snsapi_base"); data.SetValue("state", "STATE" + "#wechat_redirect"); string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl(); Log.Info(this.GetType().ToString(), "Will Redirect to URL : " + url); try { //触发微信返回code码 page.Response.Redirect(url);//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常 } catch (System.Threading.ThreadAbortException ex) { Log.Info(this.GetType().ToString(), "" + ex); } } }
/** * * 通过code换取网页授权access_token和openid的返回数据,正确时返回的JSON数据包如下: * { * "access_token":"ACCESS_TOKEN", * "expires_in":7200, * "refresh_token":"REFRESH_TOKEN", * "openid":"OPENID", * "scope":"SCOPE", * "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL" * } * 其中access_token可用于获取共享收货地址 * openid是微信支付jsapi支付接口统一下单时必须的参数 * 更详细的说明请参考网页授权获取用户基本信息:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html * @失败时抛异常WxPayException */ public void GetOpenidAndAccessTokenFromCode(string code, string AdminHotelid, int Hotelid = 0) { try { //构造获取openid及access_token的url WxPayData data = new WxPayData(); data.SetValue("appid", WxPayConfig.APPID(AdminHotelid, Hotelid)); data.SetValue("secret", WxPayConfig.APPSECRET(AdminHotelid, Hotelid)); data.SetValue("code", code); data.SetValue("grant_type", "authorization_code"); string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl(); //请求url以获取数据 string result = HttpService.Get(url); Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode response : " + result); //保存access_token,用于收货地址获取 JsonData jd = JsonMapper.ToObject(result); access_token = (string)jd["access_token"]; //获取用户openid openid = (string)jd["openid"]; Log.Debug(this.GetType().ToString(), "Get openid : " + openid); Log.Debug(this.GetType().ToString(), "Get access_token : " + access_token); } catch (Exception ex) { Log.Error(this.GetType().ToString(), ex.ToString()); throw new WxPayException(ex.ToString()); } }
public ContentResult getDecode(string openid, string city) { var pay = new JsApiPay(this.Request); var bus = new Bus(this.DataSource); string mch_id = WxPayConfig.getMCHID(city); var card = bus.GetCard(openid, WxPayConfig.APPID(city), mch_id); //乐清的订阅号appid pay.GetAccessToken("wx8a8f4c94ea99c3c6", "d08019f391fc2a7113e5efea6fc4c9dc", this.DataSource); return(Content(bus.DeCardCode(pay.access_token, card.CardId, card.CardCode))); }
protected void Page_Load(object sender, EventArgs e) { try { if (Request.QueryString["code"] != null) { string state = ""; string AdminHotelid = "1"; int Hotelid = 0; if (Request["state"] != null) { state = Server.UrlDecode(Request["state"]); } string code = Request["code"].ToString(); string postUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code"; postUrl = string.Format(postUrl, WxPayConfig.APPID(AdminHotelid, Hotelid), WxPayConfig.APPSECRET(AdminHotelid, Hotelid), code); string returnJason = GetJson(postUrl); //获取返回信息 JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> json = (Dictionary <string, object>)serializer.DeserializeObject(returnJason); object value; string openid; if (json.TryGetValue("openid", out value)) { openid = value.ToString(); Session["zdyopenid"] = openid.ToString(); Session["zdyopenid_user"] = openid.ToString(); Session.Timeout = 60 * 60 * 24; } string accessToken = ""; if (json.TryGetValue("access_token", out value)) { accessToken = value.ToString(); } string url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", accessToken.Trim(), Session["zdyopenid_user"].ToString().Trim()); string data = GetJson(url); Dictionary <string, object> json1 = (Dictionary <string, object>)serializer.DeserializeObject(data); Session["zdyInfo"] = json1; Response.Redirect(state, false); } } catch (Exception ee) { Log.Info("智订云获取用户信息报错:", ee.Message); } }
/** * * 获取收货地址js函数入口参数,详情请参考收货地址共享接口:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_9 * @return string 共享收货地址js函数需要的参数,json格式可以直接做参数使用 */ public string GetEditAddressParameters(string AdminHotelid, int Hotelid = 0) { string parameter = ""; try { string host = page.Request.Url.Host; string path = page.Request.Path; string queryString = page.Request.Url.Query; //这个地方要注意,参与签名的是网页授权获取用户信息时微信后台回传的完整url string url = "http://" + host + path + queryString; //构造需要用SHA1算法加密的数据 WxPayData signData = new WxPayData(); signData.SetValue("appid", WxPayConfig.APPID(AdminHotelid, Hotelid)); signData.SetValue("url", url); signData.SetValue("timestamp", WxPayApi.GenerateTimeStamp()); signData.SetValue("noncestr", WxPayApi.GenerateNonceStr()); signData.SetValue("accesstoken", access_token); string param = signData.ToUrl(); //Log.Debug(this.GetType().ToString(), "SHA1 encrypt param : " + param); //SHA1加密 string addrSign = FormsAuthentication.HashPasswordForStoringInConfigFile(param, "SHA1"); //Log.Debug(this.GetType().ToString(), "SHA1 encrypt result : " + addrSign); //获取收货地址js函数入口参数 WxPayData afterData = new WxPayData(); afterData.SetValue("appId", WxPayConfig.APPID(AdminHotelid, Hotelid)); afterData.SetValue("scope", "jsapi_address"); afterData.SetValue("signType", "sha1"); afterData.SetValue("addrSign", addrSign); afterData.SetValue("timeStamp", signData.GetValue("timestamp")); afterData.SetValue("nonceStr", signData.GetValue("noncestr")); //转为json格式 parameter = afterData.ToJson(); //Log.Debug(this.GetType().ToString(), "Get EditAddressParam : " + parameter); } catch (Exception ex) { Log.Error(this.GetType().ToString(), ex.ToString()); throw new WxPayException(ex.ToString()); } return(parameter); }
public WxPayData ReceiveSign(WxPayData res, string city = "") { string plan_id = res.GetValue("plan_id").ToString(); city = (plan_id == "107402") ? "杭州市2" : city; Log.Write("recesion" + city, res.ToXml()); var openid = res.GetValue("openid").ToString(); string mch_id = res.GetValue("mch_id").ToString(); if (res.IsSet("return_code") && res.IsSet("result_code")) { string return_code = res.GetValue("return_code").ToString().ToLower().Trim(); string result_code = res.GetValue("result_code").ToString().ToLower().Trim(); if (return_code.Equals("success") && result_code.Equals("success")) { var Entrustinfo = this.GetEntrustinfo(openid, WxPayConfig.APPID(city), mch_id); if (Entrustinfo != null) { Entrustinfo.DataDriver = this.DataSource; Entrustinfo.FldSigndata = res.ToXml(); string change_type = res.GetValue("change_type").ToString().ToLower(); Entrustinfo.FldChangeType = change_type.Equals("add") ? 1 : 0; Entrustinfo.FldContractId = res.GetValue("contract_id").ToString(); Entrustinfo.FldMchId = res.GetValue("mch_id").ToString(); try { Entrustinfo.FldOperateTime = DateTime.Parse(res.GetValue("operate_time").ToString()); Entrustinfo.FldContractExpiredTime = DateTime.Parse(res.GetValue("contract_expired_time").ToString()); } catch { Entrustinfo.FldRequestSerial = res.GetValue("request_serial").ToString(); } Entrustinfo.Store(); } } } WxPayData pres = new WxPayData(); pres.SetValue("return_code", "SUCCESS"); pres.SetValue("return_msg", "回调成功"); return(pres); }
/** * 生成扫描支付模式一URL * @param productId 商品ID * @return 模式一URL */ public string GetPrePayUrl(string productId, string AdminHotelid, int Hotelid = 0) { Log.Info(this.GetType().ToString(), "Native pay mode 1 url is producing..."); WxPayData data = new WxPayData(); data.SetValue("appid", WxPayConfig.APPID(AdminHotelid, Hotelid)); //公众帐号id data.SetValue("mch_id", WxPayConfig.MCHID(AdminHotelid, Hotelid)); //商户号 data.SetValue("time_stamp", WxPayApi.GenerateTimeStamp()); //时间戳 data.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //随机字符串 data.SetValue("product_id", productId); //商品ID data.SetValue("sign", data.MakeSign(AdminHotelid, Hotelid)); //签名 string str = ToUrlParams(data.GetValues()); //转换为URL串 string url = "weixin://wxpay/bizpayurl?" + str; Log.Info(this.GetType().ToString(), "Get native pay mode 1 url : " + url); return(url); }
/// <summary> /// 绑定手机号 /// </summary> /// <param name="openid"></param> /// <param name="mobile"></param> /// <param name="code"></param> /// <returns></returns> public JsonResult BindMobile(string openid, string mobile, string code, string nickname, string city) { bool result = false, needCheck = (ConfigurationManager.AppSettings["RNameNeedCheck"] == "1")?true:false; string msg = string.Empty; var bus = new Bus(this.DataSource); var user = bus.GetEntrustinfo(openid, WxPayConfig.APPID(city), WxPayConfig.getMCHID(city)); var wxuser = bus.GetUserInfo(openid, WxPayConfig.APPID(city)); var isSign = bus.isSign(openid, WxPayConfig.APPID(city), city); exterData exdata = null; var dc = new Tb_Wx_Mobilecode(this.DataSource); var obilecode = dc.FindFirst <Tb_Wx_Mobilecode>(string.Format("lower(FLD_Code)='{0}' and fld_mobile='{1}' and USED=0 order by id desc", code.ToLower(), mobile)); if (obilecode != null) { obilecode.Used = 1; obilecode.DataDriver = this.DataSource; obilecode.Store(); if (obilecode.FldExpiredTime.CompareTo(DateTime.Now) < 0) { result = false; msg = "验证码过期!"; } else { exdata = bus.Sign(openid, nickname, Request.UserHostAddress, city); user.DataDriver = this.DataSource; user.FldMobile = mobile; user.Store(); wxuser.DataDriver = this.DataSource; wxuser.Mobile = mobile; wxuser.Store(); result = true; } } else { msg = "无效验证码!"; } if (!string.IsNullOrEmpty(wxuser.Mobile) && needCheck == false) { needCheck = (wxuser.Mobile.iEqualsArr(ConfigurationManager.AppSettings["RNameCheckPhones"])) ? true : false; } return(Json(new { result = result, msg = msg, exdata = exdata, isSign = isSign, needCheck = needCheck, RNameChecked = wxuser.RNameChecked }, JsonRequestBehavior.AllowGet)); }
public WxPayData getToken(string contract_id, string city, string qrcode_hashs, int token_count = 1) { string url = "https://api.mch.weixin.qq.com/transit/gettoken"; WxPayData data = new WxPayData(); data.SetValue("appid", WxPayConfig.APPID(city)); data.SetValue("mch_id", WxPayConfig.getMCHID(city)); data.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); data.SetValue("contract_id", contract_id); data.SetValue("sign_type", "HMAC-SHA256"); data.SetValue("sign", data.MakeSign_SHA256()); data.SetValue("token_count", token_count); data.SetValue("qrcode_hashs", qrcode_hashs); string xml = HttpService.Post(data.ToXml(), url, false, 10); WxPayData res = new WxPayData(); res.FromXml(xml); return(res); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["code"] != null) { string state = ""; string AdminHotelid = "1"; int Hotelid = 0; if (Request["state"] != null) { state = Server.UrlDecode(Request["state"]); string[] urlid = state.Split('?'); //dh.sewa-power.com/Reservation/HotelDetails.aspx?AdminHotelid=SEWA006637&hotelid=36 string[] a = urlid[1].Split('&'); //AdminHotelid=SEWA006637&hotelid=36 string[] b = a[0].Split('='); //AdminHotelid=SEWA006637 string[] c = a[1].Split('='); //hotelid=36 AdminHotelid = b[1]; Hotelid = Convert.ToInt32(c[1]); } string code = Request["code"].ToString(); string postUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code"; postUrl = string.Format(postUrl, WxPayConfig.APPID(AdminHotelid, Hotelid), WxPayConfig.APPSECRET(AdminHotelid, Hotelid), code); string returnJason = GetJson(postUrl); //获取返回信息 JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> json = (Dictionary <string, object>)serializer.DeserializeObject(returnJason); object value; string openid = ""; if (json.TryGetValue("openid", out value)) { openid = value.ToString(); Session["zfzdyopenid" + AdminHotelid + Hotelid] = openid.ToString(); Session.Timeout = 60 * 60 * 24; } Log.Info("获取支付到店zfzdyopenid:" + openid + ",URL:", state); Response.Redirect(state, false); } }
public JsonResult EncryptedBindPhone(string code, string iv, string data, string nickname, string city) { var bus = new Bus(this.DataSource); var pay = new JsApiPay(this.Request); pay.GetOpenidAndSession(code, city); Phone phone = new Phone(); bool state = false; exterData exdata = null; var wxuser = bus.GetUserInfo(pay.openid, WxPayConfig.APPID(city)); var isSign = bus.isSign(pay.openid, WxPayConfig.APPID(city), city); if (!string.IsNullOrEmpty(pay.session_key)) { string result = bus.AESDecrypt(iv, pay.session_key, data); phone = Bus.JsonDeserialize <Phone>(result); state = true; wxuser.Mobile = phone.phoneNumber; wxuser.DataDriver = this.DataSource; wxuser.Store(); exdata = bus.Sign(pay.openid, nickname, Request.UserHostAddress, city); } return(Json(new { exdata = exdata, isSign = isSign, state = state, phone = phone }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 实名认证 回调 /// </summary> /// <returns></returns> public ViewResult Paycallback() { var notify = new Notify(this.Request); var res = notify.GetNotifyData(); string return_code = res.GetValue("return_code").ToString(); string result_code = res.GetValue("result_code").ToString(); WxPayData wres = new WxPayData(); if (return_code.iEquals("success") && return_code.iEquals("success")) { var openid = res.GetValue("openid").ToString(); var bus = new Bus(this.DataSource); var userinfo = bus.GetUserInfo(openid, WxPayConfig.APPID("")); if (userinfo != null) { userinfo.RNameChecked = 1; userinfo.DataDriver = this.DataSource; userinfo.Store(); } } wres.SetValue("return_code", "SUCCESS"); wres.SetValue("return_msg", "回调成功"); return(View("callback", wres)); }
/// <summary> /// 查询签约关系 /// </summary> /// <param name="contract_id"></param> /// <returns></returns> public bool QueryContract(string city, string contract_id, out string outxml) { WxPayData inputObj = new WxPayData(city); inputObj.SetValue("appid", WxPayConfig.APPID(city)); inputObj.SetValue("mch_id", WxPayConfig.getMCHID(city)); inputObj.SetValue("contract_id", contract_id); inputObj.SetValue("version", "1.0"); inputObj.SetValue("sign", inputObj.MakeSign()); string url = "https://api.mch.weixin.qq.com/papay/querycontract"; string xml = inputObj.ToXml(); string result = HttpService.Post(xml, url, false, 10); WxPayData data = new WxPayData(); data.FromXml(result); outxml = result; bool isSign = false; if (data.IsSet("contract_state") && data.GetValue("contract_state").ToString() == "0") { isSign = true; } return(isSign); }
/// <summary> /// 添加卡 /// </summary> /// <param name="openid"></param> /// <param name="city"></param> /// <returns></returns> public JsonResult addUserCard(string openid, string city) { var pay = new JsApiPay(this.Request); string appid = string.Empty, appSecret = string.Empty, card_id = string.Empty; switch (city) { case "乐清市": appid = "wx8a8f4c94ea99c3c6"; appSecret = "d08019f391fc2a7113e5efea6fc4c9dc"; card_id = "pszDVt2lJKXxOYA3alLVdbezrLTY"; break; case "常熟市": appid = "wx48a67a2aaf02f77a"; appSecret = "d788725d971438371f8a0b8c39221b2a"; card_id = "p__l8t2MvHkqBTDdGtiazSI_hSR0"; break; case "福州市": appid = "wxc20b289e21d1b606"; appSecret = "10711737c1c6b58b029f70c624bbb7e2"; card_id = "p4erJ0oPLrLMDhWcKZPLwF2Psdr8"; break; } //乐清的订阅号appid pay.GetAccessToken(appid, appSecret, this.DataSource); var bus = new Bus(this.DataSource); string mch_id = WxPayConfig.getMCHID(city); var Entrustinfo = bus.GetEntrustinfo(openid, WxPayConfig.APPID(city), mch_id); var card = bus.GetCard(openid, WxPayConfig.APPID(city), mch_id); string result = string.Empty; bool hasCard = !string.IsNullOrEmpty(card.CardCode) && card.IsRemove == 0; /* * if (!string.IsNullOrEmpty(card.CardCode)&&card.OperateTime.AddMinutes(10).CompareTo(DateTime.Now)<0) * { * string cardstate= bus.DeCardCode(pay.access_token, card.CardId, card.CardCode); * if (cardstate.ToLower().IndexOf("\"user_card_status\": \"NORMAL\"") == -1) * { * card.DataDriver = this.DataSource; * card.IsRemove = 1; * card.Store(); * hasCard = false; * } * } */ if (!hasCard) { if (Entrustinfo != null) { WxPayData inputObj = new WxPayData(city); inputObj.SetValue("appid", WxPayConfig.APPID(city)); inputObj.SetValue("mch_id", mch_id); inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); inputObj.SetValue("contract_id", Entrustinfo.FldContractId); inputObj.SetValue("sign_type", "MD5"); inputObj.SetValue("card_id", card_id); inputObj.SetValue("openid", openid); inputObj.SetValue("sign", inputObj.MakeSign()); string url = "https://api.mch.weixin.qq.com/transit/card/addcard"; string xml = inputObj.ToXml(); result = HttpService.Post(xml, url, false, 10); WxPayData data = new WxPayData(); data.FromXml(result); card.Remark = result; card.DataDriver = this.DataSource; if (data.GetValue("return_code").ToString().iEquals("success") && data.GetValue("result_code").ToString().iEquals("success")) { card.CardId = data.GetValue("card_id").ToString(); card.CardCode = data.GetValue("card_code").ToString(); card.OperateTime = DateTime.Now; card.IsRemove = 0; } card.Store(); } string signature = "", timestamp = WxPayApi.GenerateTimeStamp(); WxPayData exdata = new WxPayData(city); exdata.SetValue("code", card.CardCode); exdata.SetValue("openid", openid); exdata.SetValue("timestamp", timestamp); //exdata.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); string ticket = bus.getTicket(appid, pay.access_token); string sign = string.Empty; string[] ArrTmp = { card.CardCode, openid, timestamp, appSecret }; //ticket Array.Sort(ArrTmp); //字典排序 string tmpStr = string.Join("", ArrTmp); sign = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1"); exdata.SetValue("signature", sign);//exdata.sha1() var cardList = new List <Card>(); var card1 = new Card(); card1.cardId = card.CardId; card1.cardExt = exdata.ToJson(); cardList.Add(card1); return(Json(new { hasCard = false, ticket = ticket, cardList = cardList, addcardCallback = result }, JsonRequestBehavior.AllowGet)); } else { //var pay = new JsApiPay(this.Request); ////乐清的订阅号appid //pay.GetAccessToken("wx8a8f4c94ea99c3c6", "d08019f391fc2a7113e5efea6fc4c9dc"); //bus.DeCardCode(pay.access_token, card.CardId, card.CardCode); } var cardList2 = new List <Cardv>(); var card2 = new Cardv(); card2.cardId = card.CardId; card2.code = card.CardCode; cardList2.Add(card2); return(Json(new { hasCard = true, cardList = cardList2 }, JsonRequestBehavior.AllowGet)); }
public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查openid和product_id是否返回 if (!notifyData.IsSet("openid") || !notifyData.IsSet("product_id")) { WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "回调数据异常"); Log.Info(this.GetType().ToString(), "The data WeChat post is error : " + res.ToXml()); page.Response.Write(res.ToXml()); return; } //调统一下单接口,获得下单结果 string openid = notifyData.GetValue("openid").ToString(); string product_id = notifyData.GetValue("product_id").ToString(); string AdminHotelid = notifyData.GetValue("AdminHotelid").ToString(); //需要处理 int Hotelid = CommonHelper.GetInt(notifyData.GetValue("AdminHotelid")); //需要处理 WxPayData unifiedOrderResult = new WxPayData(); try { unifiedOrderResult = UnifiedOrder(openid, product_id, AdminHotelid, Hotelid); } catch (Exception ex)//若在调统一下单接口时抛异常,立即返回结果给微信支付后台 { WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "统一下单失败"); Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml()); page.Response.Write(res.ToXml()); return; } //若下单失败,则立即返回结果给微信支付后台 if (!unifiedOrderResult.IsSet("appid") || !unifiedOrderResult.IsSet("mch_id") || !unifiedOrderResult.IsSet("prepay_id")) { WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "统一下单失败"); Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml()); page.Response.Write(res.ToXml()); return; } //统一下单成功,则返回成功结果给微信支付后台 WxPayData data = new WxPayData(); data.SetValue("return_code", "SUCCESS"); data.SetValue("return_msg", "OK"); data.SetValue("appid", WxPayConfig.APPID(AdminHotelid, Hotelid)); data.SetValue("mch_id", WxPayConfig.MCHID(AdminHotelid, Hotelid)); data.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); data.SetValue("prepay_id", unifiedOrderResult.GetValue("prepay_id")); data.SetValue("result_code", "SUCCESS"); data.SetValue("err_code_des", "OK"); data.SetValue("sign", data.MakeSign(AdminHotelid, Hotelid)); Log.Info(this.GetType().ToString(), "UnifiedOrder success , send data to WeChat : " + data.ToXml()); page.Response.Write(data.ToXml()); return; }
public List <Tb_Wx_Pappay> getPaypayRecord(string openid, string city, int state) { var list = new List <Tb_Wx_Pappay>(); var dc = new Tb_Wx_Pappay(this.DataSource); string condition = string.Format("FLD_OPENID='{0}' and FLD_APPLET_APPID='{1}' and FLD_STATE={2}", openid, WxPayConfig.APPID(city), state);// and FLD_MEMO='SUCCESS' if (state == 1) { condition = string.Format("FLD_OPENID='{0}' and FLD_APPLET_APPID='{1}' and FLD_STATE in(1,2)", openid, WxPayConfig.APPID(city)); } string orderby = " ORDER BY FLD_TRADE_TIME desc"; DateTime start = DateTime.Parse("2017-07-01"); TimeSpan ts = DateTime.Now - start; int Year = DateTime.Now.Year - start.Year; int Month = (DateTime.Now.Year - start.Year) * 12 + (DateTime.Now.Month - start.Month); if (state == 1) { Month = (Month > 2) ? 2 : Month;//乘车记录正常取三个月记录 } else { condition += " and fld_cleardebted=0";//未结清的取所有记录 } for (int i = 0; i <= Month; i++) { DateTime temp = DateTime.Now.AddMonths(-i); dc.TableName = string.Format("tb_wx_pappay_{0}", temp.ToString("yyyyMM")); var ilist = dc.findByCondition <Tb_Wx_Pappay>(condition + orderby); if (ilist.Count > 0) { list = list.Concat(ilist).ToList(); } } return(list); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["code"] != null) { string state = ""; string AdminHotelid = ""; if (Request["state"] != null) { state = Server.UrlDecode(Request["state"]); string[] urlid = state.Split('?'); //dh.sewa-power.com/Reservation/HotelDetails.aspx?AdminHotelid=SEWA006637&hotelid=36 string[] a = urlid[1].Split('&'); //AdminHotelid=SEWA006637&hotelid=36 string[] b = a[0].Split('='); //AdminHotelid=SEWA006637 //string[] c = a[1].Split('='); //hotelid=36 AdminHotelid = b[1]; //Hotelid = Convert.ToInt32(c[1]); } string session_zhi = "openid" + AdminHotelid; string session_unionid = "unionid" + AdminHotelid; string code = Request["code"].ToString(); string postUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code"; postUrl = string.Format(postUrl, WxPayConfig.APPID(AdminHotelid, Hotelid), WxPayConfig.APPSECRET(AdminHotelid, Hotelid), code); string returnJason = GetJson(postUrl); //获取返回信息 JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> json = (Dictionary <string, object>)serializer.DeserializeObject(returnJason); object value; string openid = ""; if (json.TryGetValue("openid", out value)) { openid = value.ToString(); Session[session_zhi] = openid.ToString(); Session["openid_user"] = openid.ToString(); Session.Timeout = 60 * 60 * 24; } string accessToken = ""; if (json.TryGetValue("access_token", out value)) { accessToken = value.ToString(); } string url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", accessToken.Trim(), openid); //string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", accessToken.Trim(), openid); string data = GetJson(url); Dictionary <string, object> json1 = (Dictionary <string, object>)serializer.DeserializeObject(data); string unionid = "0"; if (json1.TryGetValue("unionid", out value)) { unionid = value.ToString(); } Session[session_unionid] = unionid; Session["Info"] = json1; Response.Redirect(state, false); } }
public exterData Sign(string openid, string nickname, string UserHostAddress, string city) { city = (city == null) ? "" : city; var Entrustinfo = this.GetEntrustinfo(openid, WxPayConfig.APPID(city), WxPayConfig.getMCHID(city)); var wxuser = this.GetUserInfo(openid, WxPayConfig.APPID(city)); var wxpay = new WxPayApi(); var exdata = new exterData(); exdata.appid = WxPayConfig.APPID(city); exdata.mch_id = WxPayConfig.getMCHID(city); exdata.contract_code = WxPayConfig.getCityCode(city) + Convert.ToString(long.Parse("10000") + Entrustinfo.Id) + DateTime.Now.ToString("ssfff"); exdata.request_serial = Entrustinfo.Id.ToString(); string display_account = string.Empty; if (!string.IsNullOrEmpty(wxuser.Mobile) && wxuser.Mobile.Length == 11) { display_account = wxuser.Mobile.Substring(0, 3) + "****" + wxuser.Mobile.Substring(7, 4); } else { display_account = nickname; } exdata.contract_display_account = display_account; switch (city) { case "福州市": exdata.notify_url = "https://www.cmeeol.com/wechat/FZReceiveSign"; break; case "杭州市": exdata.notify_url = "https://wx.hzgolong.com/wechat/HZReceiveSign"; break; case "杭州市2": exdata.notify_url = "https://wx.hzgolong.com/wechat/wccReceiveSign"; break; default: exdata.notify_url = "https://wx.hzgolong.com/wechat/ReceiveSign"; break; } //exdata.notify_url = HttpUtility.UrlEncode(exdata.notify_url); exdata.plan_id = WxPayConfig.getPlanID(city); exdata.openid = openid; exdata.timestamp = WxPayApi.GenerateTimeStamp(); exdata.clientip = UserHostAddress; exdata.deviceid = ""; exdata.mobile = ""; exdata.email = ""; exdata.qq = ""; exdata.creid = ""; exdata.outerid = ""; WxPayData inputObj = new WxPayData(city); inputObj.SetValue("appid", WxPayConfig.APPID(city)); inputObj.SetValue("contract_code", exdata.contract_code); inputObj.SetValue("contract_display_account", exdata.contract_display_account); inputObj.SetValue("mch_id", exdata.mch_id); inputObj.SetValue("notify_url", exdata.notify_url); inputObj.SetValue("plan_id", exdata.plan_id); inputObj.SetValue("request_serial", exdata.request_serial); inputObj.SetValue("timestamp", exdata.timestamp); inputObj.SetValue("clientip", exdata.clientip); inputObj.SetValue("deviceid", ""); inputObj.SetValue("mobile", ""); inputObj.SetValue("email", ""); inputObj.SetValue("qq", ""); inputObj.SetValue("openid", openid); inputObj.SetValue("creid", ""); inputObj.SetValue("outerid", ""); if (wxuser.Mobile == "13588861726") { Log.Write("luo sign inputObj json:", inputObj.ToJson()); } exdata.sign = inputObj.MakeSign(); return(exdata); }
/// <summary> /// 是否已经认签委托扣款 /// </summary> /// <param name="code"></param> /// <returns></returns> public JsonResult IsSign(string code, string openid, string nickname, string latitude, string longitude, string city, string mode = "0") { city = (city == null) ? "" :(city == "切换城市")?"": city; bool RNameChecked = false, needCheck = (ConfigurationManager.AppSettings["RNameNeedCheck"] == "1") ? true : false; if (string.IsNullOrEmpty(openid)) { var pay = new JsApiPay(this.Request); pay.GetOpenidAndAccessToken(city); openid = pay.openid; } var bus = new Bus(this.DataSource); var isDebt = bus.isDebt(openid, city); var isSign = (!string.IsNullOrEmpty(city)) ? bus.isSign(openid, WxPayConfig.APPID(city), city) : false; var user = bus.GetEntrustinfo(openid, WxPayConfig.APPID(city), WxPayConfig.getMCHID(city)); var hzuser = bus.GetEntrustinfo(openid, WxPayConfig.APPID(city), WxPayConfig.getMCHID("杭州市")); var wxuser = bus.GetUserInfo(openid, WxPayConfig.APPID(city)); nickname = (string.IsNullOrEmpty(nickname)) ? "" : nickname; var exdata = bus.Sign(openid, nickname, Request.UserHostAddress, city); if (user != null) { user.DataDriver = this.DataSource; if (!string.IsNullOrEmpty(nickname)) { user.FldNickname = nickname; } user.FldLatitude = latitude; if (!string.IsNullOrEmpty(city)) { user.FldCity = city.Replace("undefined", ""); } user.FldLongitude = longitude; user.Store(); } if (wxuser != null) { wxuser.DataDriver = this.DataSource; if (!string.IsNullOrEmpty(nickname)) { wxuser.Nickname = nickname; } wxuser.City = city; wxuser.Latitude = latitude; wxuser.Longitude = longitude; if (string.IsNullOrEmpty(wxuser.Mobile) && hzuser != null && !string.IsNullOrEmpty(hzuser.FldMobile)) { wxuser.Mobile = hzuser.FldMobile; } wxuser.Store(); RNameChecked = wxuser.RNameChecked == 1 ? true : false; } var wxpay = new WxPayApi(); bool bindMobile = !string.IsNullOrEmpty(wxuser.Mobile); if (!string.IsNullOrEmpty(wxuser.Mobile) && needCheck == false) { needCheck = (wxuser.Mobile.iEqualsArr(ConfigurationManager.AppSettings["RNameCheckPhones"])) ? true : false; } string[] valarray = new string[] { "乐清市" }; // new string[] { "乐清市", "杭州市" }; string[] keyarray = new string[] { "乐清城市公交乘车码" }; //new string[] { "乐清城市公交乘车码", "杭州城市公交乘车码" }; bool showcard = nickname.iEqualsArr("司令大人,XLsn0w,xiangling别") ? true : false; switch (mode) { case "1": valarray = new string[] { "乐清市", "常熟市" }; keyarray = new string[] { "乐清城市公交乘车码", "常熟城市公交乘车码" }; break; case "2": valarray = new string[] { "杭州市" }; keyarray = new string[] { "演示" }; break; case "3": valarray = new string[] { "福州市" }; keyarray = new string[] { "福州市" }; break; } return(Json(new { exdata = exdata, isSign = isSign, openid = openid, TimeStamp = WxPayApi.GenerateTimeStamp(), bindMobile = bindMobile, RNameChecked = RNameChecked, needCheck = needCheck, isDebt = isDebt, valarray = valarray, keyarray = keyarray, showcard = showcard }, JsonRequestBehavior.AllowGet)); }