Пример #1
0
 //method: 获取 jsapi_ticket
 //help  : http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
 //url   : https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi
 //resp  : { "errcode":0, "errmsg":"ok", "ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA", "expires_in":7200 }
 public static WechatResponseWrapper<WechatJsapiTicket> GetJsapiTicket(String accessToken) {
     String reqUrl = String.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi",
         accessToken);
     String respText = new Curl().Get(reqUrl);
     //String respText = "{\"access_token\":\"-Ribi5K3sIZ3bgUrORlWu0BJDy7vS5JW2OYm8JYKEjG1luoNrsibj8kZHAdTp8Bc0Vpy9JdUxg013rKkM13ZAQ\",\"expires_in\":7200}";
     return new WechatResponseWrapper<WechatJsapiTicket>(reqUrl, respText);
 }
Пример #2
0
 //method: 获取access token
 //help  : http://mp.weixin.qq.com/wiki/15/54ce45d8d30b6bf6758f68d2e95bc627.html
 //url   : https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
 //result: {"access_token":"ACCESS_TOKEN","expires_in":7200}
 public static WechatResponseWrapper<WechatAccessToken> GetAccessToken(String appId, String appSecret) {
     String reqUrl = String.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}",
         appId, appSecret);
     String respText = new Curl().Get(reqUrl);
     //String respText = "{\"access_token\":\"-Ribi5K3sIZ3bgUrORlWu0BJDy7vS5JW2OYm8JYKEjG1luoNrsibj8kZHAdTp8Bc0Vpy9JdUxg013rKkM13ZAQ\",\"expires_in\":7200}";
     return new WechatResponseWrapper<WechatAccessToken>(reqUrl, respText);
 }
Пример #3
0
 //method: 刷新access_token有效期
 //url   : https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN
 //result: {"access_token":"ACCESS_TOKEN", "expires_in":7200, "refresh_token":"REFRESH_TOKEN", "openid":"OPENID", "scope":"SCOPE"}
 //error : {"errcode":40030,"errmsg":"invalid refresh_token"}
 public static WechatResponseWrapper<WechatAccessToken> RefreshAccessToken(String appId, String refresh_token) {
     String grant_type = "refresh_token";
     String reqUrl = String.Format("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type={1}&refresh_token={2}",
         appId, grant_type, refresh_token);
     String respText = new Curl().Get(reqUrl);
     //String respText = "{\"access_token\":\"-Ribi5K3sIZ3bgUrORlWu0BJDy7vS5JW2OYm8JYKEjG1luoNrsibj8kZHAdTp8Bc0Vpy9JdUxg013rKkM13ZAQ\",\"expires_in\":7200}";
     return new WechatResponseWrapper<WechatAccessToken>(reqUrl, respText);
 }
Пример #4
0
 //method: 自定义菜单查询接口
 //url   : http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%9F%A5%E8%AF%A2%E6%8E%A5%E5%8F%A3        
 public static WechatResponseWrapper<WechatCustomMenu> GetCustomMenu(String acessToken) {
     //https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN
     String reqUrl = String.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", acessToken);
     String respText = new Curl().Get(reqUrl);
     return new WechatResponseWrapper<WechatCustomMenu>(reqUrl, respText);
 }
Пример #5
0
 //method: 拉取用户信息(需scope为 snsapi_userinfo)
 //url   : https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN              
 public static WechatResponseWrapper<WechatUserInfo> GetUserBaseInfoViaAuth(String acessToken, String openId) {
     String reqUrl = String.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN",
         acessToken, openId);
     String respText = new Curl().Get(reqUrl);
     return new WechatResponseWrapper<WechatUserInfo>(reqUrl, respText);
 }
Пример #6
0
 //method: 通过code换取网页授权access_token
 //url   : https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
 public static WechatResponseWrapper<WechatAuthToken> GetAuthToken(String appId, String appSecret, String code) {
     String reqUrl = String.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code",
        appId, appSecret, code);
     String respText = new Curl().Get(reqUrl);
     return new WechatResponseWrapper<WechatAuthToken>(reqUrl, respText);
 }
Пример #7
0
        //method: 发送客服消息
        //help  : http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
        //url   : https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN

        public static WechatResponseWrapper SendCustomMessage(String acessToken, WechatSendMessage message) {
            String reqUrl = String.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}",
                acessToken);
            String respText = new Curl().Post(reqUrl, JsonConvert.SerializeObject(message));
            return new WechatResponseWrapper(reqUrl, respText);
        }
Пример #8
0
 public static WechatResponseWrapper CreateCustomMenu(String acessToken, WechatMenuButtonSet menu) {
     //https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
     String reqUrl = String.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", acessToken);
     JsonSerializerSettings settings = new JsonSerializerSettings();
     settings.NullValueHandling = NullValueHandling.Ignore;
     String respText = new Curl().Post(reqUrl, JsonConvert.SerializeObject(menu, settings));
     return new WechatResponseWrapper(reqUrl, respText);
 }
Пример #9
0
 //method: 检验授权凭证(access_token)是否有效
 //url   : https://api.weixin.qq.com/sns/auth?access_token=ACCESS_TOKEN&openid=OPENID
 //result: {"errcode":0,"errmsg":"ok"}
 public static WechatResponseWrapper VerifyAccessToken(String access_token, String openid) {
     String reqUrl = String.Format("https://api.weixin.qq.com/sns/auth?access_token={0}&openid={1}",
         access_token, openid);
     String respText = new Curl().Get(reqUrl);
     return new WechatResponseWrapper(reqUrl, respText);
 }