public bool GetUserInfo(out string result, out UserInfo userInfo) { result = string.Empty; userInfo = null; if (string.IsNullOrEmpty(AccessToken) || string.IsNullOrEmpty(OpenId)) { return(false); } bool flag = false; string url = string.Format("{0}?access_token={1}&uid={2}", UserInfo_Url, AccessToken, OpenId); HttpSendInfo sendInfo = new HttpSendInfo(); sendInfo.Url = url; sendInfo.Method = "Get"; sendInfo.ContentType = "application/x-www-form-urlencoded"; sendInfo.Data = ""; sendInfo.IsHttps = true; HttpReceiveInfo receiverInfo = new HttpReceiveInfo(); if (flag = HttpHelper.Send(sendInfo, out receiverInfo) && !string.IsNullOrEmpty(receiverInfo.Result)) { result = receiverInfo.Result; userInfo = JsonHelper.Deserialize <UserInfo>(result); } return(flag); }
public bool GetAccessTokenByCode(string code) { if (string.IsNullOrEmpty(AppId) || string.IsNullOrEmpty(AppKey) || string.IsNullOrEmpty(code) || string.IsNullOrEmpty(CallbackUrl)) { return(false); } bool flag = false; string result = string.Empty; HttpSendInfo sendInfo = new HttpSendInfo(); sendInfo.Url = AccessToken_Url; sendInfo.Method = "Post"; sendInfo.ContentType = "application/x-www-form-urlencoded"; sendInfo.Data = string.Format("grant_type=authorization_code&client_id={0}&client_secret={1}&code={2}&redirect_uri={3}", AppId, AppKey, code, CallbackUrl); sendInfo.IsHttps = true; HttpReceiveInfo receiverInfo = new HttpReceiveInfo(); if (flag = HttpHelper.Send(sendInfo, out receiverInfo) && !string.IsNullOrEmpty(receiverInfo.Result)) { try { TokenInfo tokenInfo = JsonHelper.Deserialize <TokenInfo>(receiverInfo.Result); if (tokenInfo != null) { AccessToken = tokenInfo.access_token; OpenId = tokenInfo.uid; } } catch { } } return(flag); }
public string GetSessionInfo(string appId, string appSecret, string code) { var apiUrlFmt = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code"; var apiUrl = string.Format(apiUrlFmt, appId, appSecret, code); HttpReceiveInfo respInfo; HttpSendInfo reqInfo = new HttpSendInfo { Method = "get", Url = apiUrl }; HttpHelper.Send(reqInfo, out respInfo); return(respInfo.Result); }
public ActionResult Index3() { string result = ""; ErrorMessage errorMessage = ErrorMessage.失败; string url = StringHelper.GetHost(); if (string.IsNullOrEmpty(url)) { errorMessage = ErrorMessage.订单初始化失败; return(Redirect(string.Format("/error/index?errCode={0}&returnUrl=", (int)errorMessage).GetChannelRouteUrl(RouteChannelId))); } int payType = 0; string orderId = ""; int money = 0; int userType = 0; if (PayContext.VerifyPayOrderInfo(10, out errorMessage, out payType, out orderId, out money, out userType) && payType == 13 && StringHelper.GetUserAgent().ToLower().Contains("micromessenger")) { string OpenId = UrlParameterHelper.GetParams("OpenId"); if (!string.IsNullOrEmpty(OpenId)) { string appId = NowPayConfig.WeChatQrCodeAppId; string appKey = NowPayConfig.WeChatQrCodeAppKey; string callbackUrl = NowPayConfig.NewCallbackUrl; string notifyUrl = string.Format("http://{0}/user/order/paynow/notify", url); string frontNotifyUrl = string.Format("http://{0}/user/order/paynow/result", url); SortedDictionary <string, string> dict = new SortedDictionary <string, string>(); dict.Add("funcode", "WP001"); //功能码(定值:WP001)(必填) dict.Add("appId", appId); //商户应用唯一标识(字符,长度1-40)(必填) dict.Add("mhtOrderNo", orderId); //商户订单号(字符,长度1-40)(必填) dict.Add("mhtOrderName", GetName(money)); //商户商品名称(字符,长度1-40)(必填) dict.Add("mhtOrderType", "01"); //商户交易类型(01普通消费)(字符,长度1-40)(必填) dict.Add("mhtCurrencyType", "156"); //商户订单币种类型(156人民币)(字符,长度3)(必填) dict.Add("mhtOrderAmt", StringHelper.ToString(money)); //商户订单交易金额(单位(人民币):分)(数字,长度22)(必填) dict.Add("mhtOrderDetail", "充值"); //商户订单详情(字符,长度0-200)(必填) dict.Add("mhtOrderTimeOut", "3600"); //商户订单超时时间(60~3600秒,默认3600)(数字,长度4)(必填) dict.Add("mhtOrderStartTime", DateTime.Now.ToString("yyyyMMddHHmmss")); //商户订单开始时间 yyyyMMddHHmmss(字符,长度14)(必填) dict.Add("notifyUrl", notifyUrl); //商户后台通知URL(HTTP协议或者HTTPS协议,POST方式提交报文)(字符,长度1-200)(必填) dict.Add("frontNotifyUrl", frontNotifyUrl); //商户前台通知URL(HTTP协议或者HTTPS协议,POST方式提交报文)(字符,长度1-200)(必填) dict.Add("mhtCharset", "UTF-8"); //商户字符编码(字符,长度1-16)(必填) dict.Add("deviceType", "08"); //设备类型(06手机网页)(字符,长度2)(必填) dict.Add("outputType", "1"); //输出类型(二维码 = 1) dict.Add("payChannelType", payType.ToString()); //用户所选渠道类型(如果为空则直接使用现在支付收银台页面,如果不为空则直接跳转至支付渠道(银联或者支付宝等))(字符,长度2) dict.Add("mhtReserved", ""); //商户保留域(给商户使用的字段,商户可以对交易进行标记,现在支付将原样返回)(字符,长度100) dict.Add("consumerId", StringHelper.ToString(currentUser.UserId)); //消费者ID(消费者在商户系统的ID,非必填,但是推荐填写,以便于辅助数据分析)(字符,长度40) dict.Add("consumerName", ""); //消费者名称(消费者在商户系统的名称,非必填,但是推荐填写,以便于辅助数据分析)(字符,长度40) dict.Add("mhtSignType", "MD5"); //商户签名方法(定值:MD5)(必填) dict.Add("mhtSignature", GetSign(appKey, dict)); //商户数据签名(MAX64TEXT)(必填) HttpSendInfo sendInfo = new HttpSendInfo(); sendInfo.Method = "POST"; sendInfo.Url = callbackUrl; sendInfo.Data = GetPostData(dict); HttpReceiveInfo receiveInfo = new HttpReceiveInfo(); if (HttpHelper.Send(sendInfo, out receiveInfo)) { //报文日志 //Log(this.Server.UrlDecode(sendInfo.Data)); result = GetTnUrl3(receiveInfo.Result); } } } ViewData.Model = result; ViewBag.OrderId = orderId; return(View()); }