示例#1
0
 /// <summary>
 /// 生成JSSDK_API调用用到的票据
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="errMsg">出错信息</param>
 /// <returns></returns>
 public static string BuildJsApiTickets(string accessToken, out string errMsg)
 {
     errMsg = "";
     try
     {
         string    url       = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={0}", accessToken);
         IHttpForm _httpForm = new HttpForm("", 1500, true, 8);
         url += "&rnd=" + Guid.NewGuid().ToString();
         HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
         {
             Url = url
         });
         Dictionary <object, object> dict = JsonConvert.DeserializeObject <Dictionary <object, object> >(_response.Response);
         if (dict.ContainsKey("ticket"))
         {
             return(dict["ticket"].ToString());
         }
         errMsg = string.Format("获取JsApiTickets失败:{0}", _response.Response);
         return("");
     }
     catch (Exception ex)
     {
         errMsg = string.Format("BuildJsApiTickets异常::{0}|{1}", ex.Message, ex.StackTrace);
         return("");
     }
 }
示例#2
0
 /// <summary>
 /// 生成微信AccessToken
 /// </summary>
 /// <param name="appId">ID</param>
 /// <param name="appSecret">秘钥</param>
 /// <param name="errMsg">出错信息</param>
 /// <returns></returns>
 public static string BuildAccessToken(string appId, string appSecret, out string errMsg)
 {
     errMsg = "";
     try
     {
         string    url       = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appId, appSecret);
         IHttpForm _httpForm = new HttpForm("", 15000, true, 8);
         url += "&rnd=" + Guid.NewGuid().ToString();
         HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
         {
             Url = url
         });
         Dictionary <object, object> dict = JsonConvert.DeserializeObject <Dictionary <object, object> >(_response.Response);
         if (dict.ContainsKey("access_token"))
         {
             return(dict["access_token"].ToString());
         }
         errMsg = string.Format("获取AccessToken失败:{0}", _response.Response);
         return("");
     }
     catch (Exception ex)
     {
         errMsg = string.Format("BuildAccessToken异常:{0}|{1}", ex.Message, ex.StackTrace);
         return("");
     }
 }
示例#3
0
        /// <summary>
        /// 获取access_token,获取授权,返回json数据
        /// </summary>
        private string GetGrantTypeRequest(string appid, string appsecret, int flag)
        {
            string url = string.Empty;

            if (flag == 2)
            {
                url = string.Format("https://api.yixin.im/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, appsecret);
            }
            else if (flag == 1)
            {
                url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, appsecret);
            }
            else if (flag == 3)
            {
                return("");
            }
            IHttpForm        _httpForm = new HttpForm(managerSiteAddr, 1500, true, 8);
            HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
            {
                Url = url
            });
            string json = _response.Response.ToString();

            return(json);
        }
示例#4
0
        /// <summary>
        /// 自定义菜单get请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="access_token"></param>
        /// <returns></returns>
        private string MenuRequest(string url, string access_token)
        {
            IHttpForm        _httpForm = new HttpForm(managerSiteAddr, 1500, true, 8);
            HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
            {
                Url = url
            });
            string json = _response.Response.ToString();

            return(json);
        }
示例#5
0
        public string BuildAccessToken(string appid, string appsecret, int customerId)
        {
            string           url       = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, appsecret);
            IHttpForm        _httpForm = new HttpForm("", 15000, true, 8);
            HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
            {
                Url = url
            });
            Dictionary <object, object> dict = JsonConvert.DeserializeObject <Dictionary <object, object> >(_response.Response);

            if (dict.ContainsKey("access_token"))
            {
                return(dict["access_token"].ToString());
            }
            throw new Exception(string.Format("非Senparc获取AccessToken失败->appid:{0},appsecret:{1},商户Id:{2}", appid, appsecret, customerId));
        }
示例#6
0
文件: MPHelper.cs 项目: Daqiv/sayhi
 /// <summary>
 /// 获取微信用户基本信息(包括UnionID机制)
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="openid"></param>
 /// <returns></returns>
 public static MPUserInfoResult GetWxUserInfo(string wxApiUrl, out string errmsg)
 {
     errmsg = "";
     try
     {
         IHttpForm        _httpForm = new HttpForm("HOT-MPHelper", 15000, true, 8);
         HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
         {
             Url = wxApiUrl
         });
         MPUserInfoResult result = JsonConvert.DeserializeObject <MPUserInfoResult>(_response.Response);
         return(result);
     }
     catch (Exception ex)
     {
         errmsg = ex.Message;
         LogHelper.Write("获取微信用户基本信息(GetWxUserInfo)异常 -->:" + ex.Message);
         return(null);
     }
 }
示例#7
0
 private string BuildTicket(string accessToken)
 {
     try
     {
         string           url       = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={0}", accessToken);
         IHttpForm        _httpForm = new HttpForm("", 1500, true, 8);
         HttpFormResponse _response = _httpForm.Get(new HttpFormGetRequest()
         {
             Url = url
         });
         Dictionary <object, object> dict = JsonHelper.JsonDeserialize <Dictionary <object, object> >(_response.Response);
         if (dict.ContainsKey("ticket"))
         {
             return(dict["ticket"].ToString());
         }
         LogHelper.Log("GetTicket(获取jsapi_ticket失败):" + _response.Response, LogHelperTag.ERROR);
         return("");
     }
     catch (Exception ex)
     {
         LogHelper.Log("WxJsApiTicketProvider->GetTicket(string accessToken)报错:" + ex.Message + "|accessToken:" + accessToken, LogHelperTag.ERROR);
         return("");
     }
 }