//群发消息 BasicApi.GetTokenSession(AppID, AppSecret);
        public static List <string> SentGoup(string AppID, string AppSecret)
        {
            string        access_token = BasicApi.GetTokenSession(AppID, AppSecret);
            List <string> openidList   = OAuth2.GetOpenIDs(access_token);

            return(openidList);
        }
Example #2
0
        /// <summary>
        /// 用openid换取用户信息
        /// </summary>
        /// <param name="openid">微信标识id</param>
        /// <returns></returns>
        public Dictionary <string, object> GetUserInfoForopenid(string Appid, string Appsecret, string openid)
        {
            JavaScriptSerializer Jss = new JavaScriptSerializer();
            string access_token      = BasicApi.GetTokenSession(Appid, Appsecret); //获取access_token
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", access_token, openid);
            Dictionary <string, object> respDic = (Dictionary <string, object>)Jss.DeserializeObject(CommonMethod.WebRequestPostOrGet(url, ""));

            return(respDic);
        }
        /// <summary>
        /// 发布菜单
        /// </summary>
        /// <param name="MenuJson">配置的菜单json数据</param>
        /// <param name="AppID">AppID</param>
        /// <param name="AppSecret">AppSecret</param>
        /// <returns>返回0成功否则错误码</returns>
        public string MenuCreate(string MenuJson, string AppID, string AppSecret)
        {
            string setMenuUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";

            setMenuUrl = string.Format(setMenuUrl, BasicApi.GetTokenSession(AppID, AppSecret));//获取token、拼凑url

            string respText = CommonMethod.WebRequestPostOrGet(setMenuUrl, MenuJson);
            Dictionary <string, object> respDic = (Dictionary <string, object>)Jss.DeserializeObject(respText);

            return(respDic["errcode"].ToString());//返回0发布成功
        }
Example #4
0
 private void CreateMenu(string MenuJson, string AppID, string AppSecret)
 {
     string access_token = BasicApi.GetTokenSession(AppID, AppSecret);
     string i            = GetPage("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token, MenuJson);
 }
Example #5
0
        /// <summary>
        /// 获取JsApi权限配置的数组/四个参数
        /// </summary>
        /// <param name="Appid">应用id</param>
        /// <param name="Appsecret">密钥</param>
        /// <returns>json格式的四个参数</returns>
        public string GetJsApiInfo(string Appid, string Appsecret)
        {
            string timestamp    = CommonMethod.ConvertDateTimeInt(DateTime.Now).ToString();          //生成签名的时间戳
            string nonceStr     = CommonMethod.GetRandCode(16);                                      //生成签名的随机串
            string url          = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.ToString(); //当前的地址
            string jsapi_ticket = "";

            //ticket 缓存7200秒
            if (System.Web.HttpContext.Current.Session["jsapi_ticket"] == null)
            {
                jsapi_ticket = CommonMethod.WebRequestPostOrGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + BasicApi.GetTokenSession(Appid, Appsecret) + "&type=jsapi", "");
                System.Web.HttpContext.Current.Session["jsapi_ticket"] = jsapi_ticket;
                System.Web.HttpContext.Current.Session.Timeout         = 7200;
            }
            else
            {
                jsapi_ticket = System.Web.HttpContext.Current.Session["jsapi_ticket"].ToString();
            }
            Dictionary <string, object> respDic = (Dictionary <string, object>)Jss.DeserializeObject(jsapi_ticket);

            jsapi_ticket = respDic["ticket"].ToString();//获取ticket
            string[] ArrayList = { "jsapi_ticket=" + jsapi_ticket, "timestamp=" + timestamp, "noncestr=" + nonceStr, "url=" + url };
            Array.Sort(ArrayList);
            string signature = string.Join("&", ArrayList);

            signature = FormsAuthentication.HashPasswordForStoringInConfigFile(signature, "SHA1").ToLower();
            return("{\"appId\":\"" + Appid + "\", \"timestamp\":" + timestamp + ",\"nonceStr\":\"" + nonceStr + "\",\"signature\":\"" + signature + "\"}");
        }