org.jeewx.api.core.exception.WexinReqException Java Examples
The following examples show how to use
org.jeewx.api.core.exception.WexinReqException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeixinReqMenuCreateHandler.java From jeewx-api with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public String doRequest(WeixinReqParam weixinReqParam) throws WexinReqException{ // TODO Auto-generated method stub String strReturnInfo = ""; if(weixinReqParam.getClass().isAnnotationPresent(ReqType.class)){ ReqType reqType = weixinReqParam.getClass().getAnnotation(ReqType.class); WeixinReqConfig objConfig = WeiXinReqUtil.getWeixinReqConfig(reqType.value()); if(objConfig != null){ String reqUrl = objConfig.getUrl(); MenuCreate mc = (MenuCreate) weixinReqParam; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("access_token", mc.getAccess_token()); String jsonData = "{"+getMenuButtonJson("button",mc.getButton())+"}"; logger.info("处理创建菜单"+jsonData); strReturnInfo = HttpRequestProxy.doJsonPost(reqUrl, parameters, jsonData); } }else{ logger.info("没有找到对应的配置信息"); } return strReturnInfo; }
Example #2
Source File: JwGroupAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取所有的分组信息 * @param accesstoken * @return * @throws WexinReqException */ public static List<Group> getAllGroup(String accesstoken) throws WexinReqException{ GroupGet c = new GroupGet(); c.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(c); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); List<Group> lstGroup = null; JSONArray infoArray = result.getJSONArray(RETURN_INFO_NAME); lstGroup = new ArrayList<Group>(infoArray.size()); for(int i=0;i<infoArray.size();i++){ Group group = (Group)JSONObject.toBean(infoArray.getJSONObject(i), Group.class); if(!"未分组".equals(group.getName())){ lstGroup.add(group); } } return lstGroup; }
Example #3
Source File: JwDataCubeAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取消息发送分布数据-测试 */ private static void testGetWxDataCubeStreamMsgDistInfo(){ System.out.println("test testGetWxDataCubeStreamMsgDistInfo start "); JwDataCubeAPI s = new JwDataCubeAPI(); try { List<WxDataCubeStreamMsgDistInfo> msgInfoList = s.getWxDataCubeStreamMsgDistInfo("a8UEhkxmxN269afPJ7SuY9vVroHPYiwm9Yv5gu_yK4GGsA60IafJ3N9We4ubabgZ4lsl4kd0zqcH7JC70UsQ951Ndur4ejSIz7VvroBJn4g","2015-01-01","2015-01-15"); if(msgInfoList!=null&&msgInfoList.size()>0){ for (WxDataCubeStreamMsgDistInfo wxDataCubeStreamMsgInfo : msgInfoList) { System.out.println(wxDataCubeStreamMsgInfo.getRef_date()); System.out.println(wxDataCubeStreamMsgInfo.getCount_interval()); } } } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("test testGetWxDataCubeStreamMsgDistInfo end "); }
Example #4
Source File: OpenwxController.java From jeewx with Apache License 2.0 | 6 votes |
/** * 一键授权功能 * @param request * @param response * @throws IOException * @throws AesException * @throws DocumentException */ @RequestMapping(value = "/goAuthor") public void goAuthor(HttpServletRequest request, HttpServletResponse response) throws IOException, AesException, DocumentException { ApiComponentToken apiComponentToken = new ApiComponentToken(); apiComponentToken.setComponent_appid(COMPONENT_APPID); apiComponentToken.setComponent_appsecret(COMPONENT_APPSECRET); WeixinOpenAccountEntity entity = getWeixinOpenAccount(APPID); apiComponentToken.setComponent_verify_ticket(entity.getTicket()); try { String component_access_token = JwThirdAPI.getAccessToken(apiComponentToken); //预授权码 String preAuthCode = JwThirdAPI.getPreAuthCode(COMPONENT_APPID, component_access_token); String url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid="+COMPONENT_APPID+"&pre_auth_code="+preAuthCode+"&redirect_uri="+ResourceUtil.getConfigByName("domain")+"/rest/openwx/authorCallback"; response.sendRedirect(url); } catch (WexinReqException e) { e.printStackTrace(); } }
Example #5
Source File: JwSendMessageAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 图文消息预览 * * @param touser * 接收人openid * @param wxArticles * 图文集合 * @throws WexinReqException */ public static void messagePrivate(String accesstoken, String touser, List<WxArticle> wxArticles) throws WexinReqException { if (accesstoken != null) { String requestUrl = message_preview_url.replace("ACCESS_TOKEN", accesstoken); try { String mediaId = getMediaId(accesstoken, wxArticles); JSONObject obj = new JSONObject(); JSONObject mpnews = new JSONObject(); obj.put("touser", touser); obj.put("msgtype", "mpnews"); mpnews.put("media_id", mediaId); obj.put("mpnews", mpnews); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); } catch (Exception e) { throw new WexinReqException(e); } } else { throw new WexinReqException("accesstoken 为空,请检查!"); } }
Example #6
Source File: JwDataCubeAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取消息发送周数据-测试 */ private static void testGetWxDataCubeStreamMsgWeekInfo(){ System.out.println("test testGetWxDataCubeStreamMsgWeekInfo start "); JwDataCubeAPI s = new JwDataCubeAPI(); try { List<WxDataCubeStreamMsgWeekInfo> msgInfoList = s.getWxDataCubeStreamMsgWeekInfo("a8UEhkxmxN269afPJ7SuY9vVroHPYiwm9Yv5gu_yK4GGsA60IafJ3N9We4ubabgZ4lsl4kd0zqcH7JC70UsQ951Ndur4ejSIz7VvroBJn4g","2015-01-01","2015-01-07"); if(msgInfoList!=null&&msgInfoList.size()>0){ for (WxDataCubeStreamMsgWeekInfo wxDataCubeStreamMsgInfo : msgInfoList) { System.out.println(wxDataCubeStreamMsgInfo.getMsg_count()); System.out.println(wxDataCubeStreamMsgInfo.getMsg_type()); } } } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("test testGetWxDataCubeStreamMsgWeekInfo end "); }
Example #7
Source File: JwSendMessageAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 根据群发的msg_id删除群发<br/> * 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片。 * 另外,删除群发消息只能删除图文消息和视频消息,其他类型的消息一经发送,无法删除。 * * @param accesstoken * @param msg_id * 群发消息的msg_id * @return * @throws WexinReqException */ public static String deleteSendMessage(String accesstoken, String msg_id) throws WexinReqException { String response = null; if (accesstoken != null) { String requestUrl = message_delete_url.replace("ACCESS_TOKEN", accesstoken); try { JSONObject obj = new JSONObject(); obj.put("msg_id", msg_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); response = result.toString(); } catch (Exception e) { throw new WexinReqException(e); } } else { throw new WexinReqException("accesstoken 为空,请检查!"); } return response; }
Example #8
Source File: JwSendMessageAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 上传媒体资源 * * @param filePath * @param fileName * @param type * 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb) * @return * @throws Exception */ public static WxMediaResponse uploadMediaFile(String accesstoken, String filePath, String fileName, String type) throws WexinReqException { WxMediaResponse mediaResource = null; if (accesstoken != null) { String requestUrl = upload_media_url.replace("ACCESS_TOKEN", accesstoken).replace("TYPE", type); File file = new File(filePath + fileName); String contentType = WeiXinReqUtil.getFileContentType(fileName.substring(fileName.lastIndexOf(".") + 1)); JSONObject result = WxstoreUtils.uploadMediaFile(requestUrl, file, contentType); //System.out.println("微信返回的结果:" + result.toString()); if (result.containsKey("errcode")) { logger.error("上传媒体资源失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { // {"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789} mediaResource = new WxMediaResponse(); mediaResource.setMedia_id(result.getString("media_id")); mediaResource.setType(result.getString("type")); mediaResource.setCreated_at(new Date(result.getLong("created_at") * 1000)); } // return mediaResource; } return mediaResource; }
Example #9
Source File: JwMessageCommentAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 开启评论 * @param accesstoken * @param msg_data_id * @param index * @throws WexinReqException * @return { “errcode”: ERRCODE, “errmsg” : ERRMSG } */ public static JSONObject openComment(String accesstoken,String msg_data_id,int index) throws WexinReqException { if (accesstoken != null) { String requestUrl = comment_open_url.replace("ACCESS_TOKEN", accesstoken); try { JSONObject obj = new JSONObject(); obj.put("msg_data_id", msg_data_id); obj.put("index", index); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); System.out.println("微信返回的结果:" + result.toString()); return result; } catch (Exception e) { throw new WexinReqException(e); } } else { throw new WexinReqException("accesstoken 为空,请检查!"); } }
Example #10
Source File: JwMessageCommentAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 将评论标记精选 * @param accesstoken * @param msg_data_id 群发返回的msg_data_id * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 * @param user_comment_id 用户评论id * @return * { “errcode”: ERRCODE, “errmsg” : ERRMSG } * <p> * <br>{ “errcode” : 45009, “errmsg” : “reach max api daily quota limit” //没有剩余的调用次数 } * <br>{ “errcode” : 88000, “errmsg” : “open comment without comment privilege” //没有留言权限 } * <br>{ “errcode” : 88001, “errmsg” : “msg_data is not exists” //该图文不存在 } * <br>{ “errcode” : 88003, “errmsg” : “elected comment upper limit” //精选评论数已达上限 } * <br>{ “errcode” : 88004, “errmsg” : “comment was deleted by user” //已被用户删除,无法精选 } * <br>{ “errcode” : 88008, “errmsg” : “comment is not exists” //该评论不存在 } * @throws WexinReqException */ public static JSONObject markelectComment(String accesstoken,String msg_data_id,int index,String user_comment_id) throws WexinReqException { if (accesstoken == null) { throw new WexinReqException("accesstoken 为空,请检查!"); } String requestUrl = comment_markelect.replace("ACCESS_TOKEN", accesstoken); try { JSONObject obj = new JSONObject(); obj.put("msg_data_id", msg_data_id); obj.put("index", index); obj.put("user_comment_id", user_comment_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); logger.info("将评论标记精选:" + result.toString()); return result; } catch (Exception e) { throw new WexinReqException(e); } }
Example #11
Source File: JwMessageCommentAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 将评论取消精选 * @param accesstoken * @param msg_data_id 群发返回的msg_data_id * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 * @param user_comment_id 用户评论id * @return * { “errcode”: ERRCODE, “errmsg” : ERRMSG } * <p> * <br>{ “errcode” : 45009, “errmsg” : “reach max api daily quota limit” //没有剩余的调用次数 } * <br>{ “errcode” : 88000, “errmsg” : “open comment without comment privilege” //没有留言权限 } * <br>{ “errcode” : 88001, “errmsg” : “msg_data is not exists” //该图文不存在 } * <br>{ “errcode” : 88008, “errmsg” : “comment is not exists” //该评论不存在 } * @throws WexinReqException */ public static JSONObject unmarkelectComment(String accesstoken,String msg_data_id,int index,String user_comment_id) throws WexinReqException { if (accesstoken == null) { throw new WexinReqException("accesstoken 为空,请检查!"); } String requestUrl = comment_unmarkelect.replace("ACCESS_TOKEN", accesstoken); try { JSONObject obj = new JSONObject(); obj.put("msg_data_id", msg_data_id); obj.put("index", index); obj.put("user_comment_id", user_comment_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); logger.info("将评论取消精选:" + result.toString()); return result; } catch (Exception e) { throw new WexinReqException(e); } }
Example #12
Source File: JwMessageCommentAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 删除评论 * @param accesstoken * @param msg_data_id 群发返回的msg_data_id * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 * @param user_comment_id 评论id * @return * { “errcode”: ERRCODE, “errmsg” : ERRMSG } * <p> *<br>{ “errcode” : 45009, “errmsg” : “reach max api daily quota limit” //没有剩余的调用次数 } *<br>{ “errcode” : 88000, “errmsg” : “open comment without comment privilege” //没有留言权限 } *<br>{ “errcode” : 88001, “errmsg” : “msg_data is not exists” //该图文不存在 } *<br>{ “errcode” : 88008, “errmsg” : “comment is not exists” //该评论不存在 } * @throws WexinReqException */ public static JSONObject deleteComment(String accesstoken,String msg_data_id,int index,String user_comment_id) throws WexinReqException { if (accesstoken == null) { throw new WexinReqException("accesstoken 为空,请检查!"); } String requestUrl = comment_delete.replace("ACCESS_TOKEN", accesstoken); try { JSONObject obj = new JSONObject(); obj.put("msg_data_id", msg_data_id); obj.put("index", index); obj.put("user_comment_id", user_comment_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); logger.info("删除评论:" + result.toString()); return result; } catch (Exception e) { throw new WexinReqException(e); } }
Example #13
Source File: JwMessageCommentAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 回复评论 * @param accesstoken * @param msg_data_id 群发返回的msg_data_id * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 * @param user_comment_id 评论id * @param content 回复内容 * @return * { “errcode”: ERRCODE, “errmsg” : ERRMSG } * <p> * <br>{ “errcode” : 45009, “errmsg” : “reach max api daily quota limit” //没有剩余的调用次数 } * <br>{ “errcode” : 88000, “errmsg” : “open comment without comment privilege” //没有留言权限 } * <br>{ “errcode” : 88001, “errmsg” : “msg_data is not exists” //该图文不存在 } * <br>{ “errcode” : 88005, “errmsg” : “already reply” //已经回复过了 } * <br>{ “errcode” : 88007, “errmsg” : “reply content beyond max len or content len is zero”//回复超过长度限制或为0 } * <br>{ “errcode” : 88008, “errmsg” : “comment is not exists” //该评论不存在 } * @throws WexinReqException */ public static JSONObject replyComment(String accesstoken,String msg_data_id,int index,String user_comment_id,String content) throws WexinReqException { if (accesstoken == null) { throw new WexinReqException("accesstoken 为空,请检查!"); } String requestUrl = comment_reply_add.replace("ACCESS_TOKEN", accesstoken); try { JSONObject obj = new JSONObject(); obj.put("msg_data_id", msg_data_id); obj.put("index", index); obj.put("user_comment_id", user_comment_id); obj.put("content", content); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); logger.info("回复评论:" + result.toString()); return result; } catch (Exception e) { throw new WexinReqException(e); } }
Example #14
Source File: JwDataCubeAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取消息发送分布周数据-测试 */ private static void testGetWxDataCubeStreamMsgDistWeekInfo(){ System.out.println("test testGetWxDataCubeStreamMsgDistWeekInfo start "); JwDataCubeAPI s = new JwDataCubeAPI(); try { List<WxDataCubeStreamMsgDistWeekInfo> msgInfoList = s.getWxDataCubeStreamMsgDistWeekInfo("a8UEhkxmxN269afPJ7SuY9vVroHPYiwm9Yv5gu_yK4GGsA60IafJ3N9We4ubabgZ4lsl4kd0zqcH7JC70UsQ951Ndur4ejSIz7VvroBJn4g","2015-01-01","2015-01-15"); if(msgInfoList!=null&&msgInfoList.size()>0){ for (WxDataCubeStreamMsgDistWeekInfo wxDataCubeStreamMsgInfo : msgInfoList) { System.out.println(wxDataCubeStreamMsgInfo.getRef_date()); System.out.println(wxDataCubeStreamMsgInfo.getCount_interval()); } } } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("test testGetWxDataCubeStreamMsgDistWeekInfo end "); }
Example #15
Source File: JwDataCubeAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取消息分送分时数据-测试 */ private static void testGetWxDataCubeStreamMsgHourInfo(){ System.out.println("test testGetWxDataCubeStreamMsgHourInfo start "); JwDataCubeAPI s = new JwDataCubeAPI(); try { List<WxDataCubeStreamMsgHourInfo> msgInfoList = s.getWxDataCubeStreamMsgHourInfo("a8UEhkxmxN269afPJ7SuY9vVroHPYiwm9Yv5gu_yK4GGsA60IafJ3N9We4ubabgZ4lsl4kd0zqcH7JC70UsQ951Ndur4ejSIz7VvroBJn4g","2015-01-07","2015-01-07"); if(msgInfoList!=null&&msgInfoList.size()>0){ for (WxDataCubeStreamMsgHourInfo wxDataCubeStreamMsghourInfo : msgInfoList) { System.out.println(wxDataCubeStreamMsghourInfo.getMsg_count()); System.out.println(wxDataCubeStreamMsghourInfo.getMsg_type()); System.out.println(wxDataCubeStreamMsghourInfo.getRef_hour()); } } } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("test testGetWxDataCubeStreamMsgHourInfo end "); }
Example #16
Source File: OpenWxController.java From jeewx-boot with Apache License 2.0 | 6 votes |
/** * 一键授权功能(仅支持公众号) * @param request * @param response * @throws IOException * @throws AesException * @throws DocumentException */ @RequestMapping(value = "/goAuthor") public void goAuthor(HttpServletRequest request, HttpServletResponse response) throws IOException, AesException, DocumentException { //从数据库获取ticket WeixinOpenAccount weixinOpenAccount = getWeixinOpenAccount(CommonWeixinProperties.component_appid); try { String componentAccessToken = weixinOpenAccount.getComponentAccessToken(); //预授权码 String preAuthCode = JwThirdAPI.getPreAuthCode(CommonWeixinProperties.component_appid, componentAccessToken); //auth_type:要授权的帐号类型, 1则商户扫码后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示。 String url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid="+CommonWeixinProperties.component_appid+"&pre_auth_code="+preAuthCode+"&auth_type=1"+"&redirect_uri="+CommonWeixinProperties.domain+"/rest/openwx/authorCallback"; response.sendRedirect(url); } catch (WexinReqException e) { e.printStackTrace(); } }
Example #17
Source File: JwDataCubeAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取消息发送概况数据 * @param bDate 起始时间 * @param eDate 结束时间 * @return * @throws WexinReqException */ public static List<WxDataCubeStreamMsgInfo> getWxDataCubeStreamMsgInfo(String accesstoken,String bDate,String eDate) throws WexinReqException { if (accesstoken != null) { // 封装请求参数 WxDataCubeStreamMsgParam msgParam = new WxDataCubeStreamMsgParam(); msgParam.setAccess_token(accesstoken); msgParam.setBegin_date(bDate); msgParam.setEnd_date(eDate); // 调用接口 String requestUrl = GETUPSTREAMMSG_URL.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = JSONObject.fromObject(msgParam); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); // 无错误消息时 返回数据对象 JSONArray arrayResult = result.getJSONArray("list"); // 正常返回 List<WxDataCubeStreamMsgInfo> msgInfoList = null; msgInfoList=JSONHelper.toList(arrayResult, WxDataCubeStreamMsgInfo.class); return msgInfoList; } return null; }
Example #18
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 新增其他永久素材 * @param accesstoken * @param wx * @return * @throws WexinReqException */ public static WxMediaForMaterialResponse addMediaFileByMaterialNews(String accesstoken, String type,String filePath,String fileName) throws WexinReqException { WxMediaForMaterialResponse mediaResource = null; if (accesstoken != null) { String requestUrl = add_material.replace("ACCESS_TOKEN", accesstoken); String url = requestUrl.replace("TYPE", type); File file = new File(filePath + fileName); String contentType = WeiXinReqUtil.getFileContentType(fileName.substring(fileName.lastIndexOf(".") + 1)); JSONObject result = WxstoreUtils.uploadMediaFileNews(url, file, contentType); if (result.containsKey("errcode")) { logger.error("新增其他永久素材 失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); } else { logger.info("====新增其他永久素材 成功====result:"+result.toString()); mediaResource = new WxMediaForMaterialResponse(); if("thumb".equals(type)){ mediaResource.setMedia_id(result.getString("thumb_media_id")); }else{ mediaResource.setMedia_id(result.getString("media_id")); } mediaResource.setUrl(result.getString("url")); } } return mediaResource; }
Example #19
Source File: JwThirdAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 2、获取预授权码 * @param appid * @param appscret * @return kY9Y9rfdcr8AEtYZ9gPaRUjIAuJBvXO5ZOnbv2PYFxox__uSUQcqOnaGYN1xc4N1rI7NDCaPm_0ysFYjRVnPwCJHE7v7uF_l1hI6qi6QBsA * @throws WexinReqException */ public static String getPreAuthCode(String component_appid, String component_access_token) throws WexinReqException{ String pre_auth_code = ""; String requestUrl = api_create_preauthcode_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token); GetPreAuthCodeParam getPreAuthCodeParam = new GetPreAuthCodeParam(); getPreAuthCodeParam.setComponent_appid(component_appid); JSONObject obj = JSONObject.fromObject(getPreAuthCodeParam); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); if (result.has("errcode")) { logger.error("获取权限令牌信息!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获取权限令牌信息!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { pre_auth_code = result.getString("pre_auth_code"); } return pre_auth_code; }
Example #20
Source File: Test.java From jeewx-api with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws WexinReqException, UnsupportedEncodingException { Test t = new Test(); //测试 获取用户增减数据 // t.getUserSummary(); //测试 获取累计用户数据 // t.getUserCumulate(); //测试 获取图文群发每日数据 // t.getArticleSummary(); //获取图文群发总数据 t.getArticleTotal(); //获取图文统计数据 // t.getUserRead(); //获取图文统计分时数据 // t.getUserReadHour(); //获取图文分享转发数据 // t.getUserShare(); //获取图文分享转发分时数据 // t.getUserShareHour(); }
Example #21
Source File: JwThirdAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
public static void main(String[] args){ try { //String s = JwThirdAPI.getPreAuthCode("wx5412820bba6f6bd6","unisk"); ApiComponentToken apiComponentToken = new ApiComponentToken(); //apiComponentToken.setComponent_appid("wx5412820bba6f6bd6"); apiComponentToken.setComponent_appid("wx056ae5bc88c95c55"); apiComponentToken.setComponent_appsecret("0c79e1fa963cd80cc0be99b20a18faeb"); apiComponentToken.setComponent_verify_ticket(null); String s = JwThirdAPI.getAccessToken(apiComponentToken); System.out.println(s); } catch (WexinReqException e) { e.printStackTrace(); } }
Example #22
Source File: JwDataCubeAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取消息发送分布月数据-测试 */ private static void testGetWxDataCubeStreamMsgDistMonthInfo(){ System.out.println("test testGetWxDataCubeStreamMsgDistMonthInfo start "); JwDataCubeAPI s = new JwDataCubeAPI(); try { List<WxDataCubeStreamMsgDistMonthInfo> msgInfoList = s.getWxDataCubeStreamMsgDistMonthInfo("a8UEhkxmxN269afPJ7SuY9vVroHPYiwm9Yv5gu_yK4GGsA60IafJ3N9We4ubabgZ4lsl4kd0zqcH7JC70UsQ951Ndur4ejSIz7VvroBJn4g","2015-01-01","2015-01-15"); if(msgInfoList!=null&&msgInfoList.size()>0){ for (WxDataCubeStreamMsgDistMonthInfo wxDataCubeStreamMsgInfo : msgInfoList) { System.out.println(wxDataCubeStreamMsgInfo.getRef_date()); System.out.println(wxDataCubeStreamMsgInfo.getCount_interval()); } } } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("test testGetWxDataCubeStreamMsgDistMonthInfo end "); }
Example #23
Source File: WeixinReqTemplateMessageHandler.java From jeewx-api with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public String doRequest(WeixinReqParam weixinReqParam) throws WexinReqException{ // TODO Auto-generated method stub String strReturnInfo = ""; if(weixinReqParam.getClass().isAnnotationPresent(ReqType.class)){ ReqType reqType = weixinReqParam.getClass().getAnnotation(ReqType.class); WeixinReqConfig objConfig = WeiXinReqUtil.getWeixinReqConfig(reqType.value()); if(objConfig != null){ String reqUrl = objConfig.getUrl(); IndustryTemplateMessageSend mc = (IndustryTemplateMessageSend) weixinReqParam; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("access_token", mc.getAccess_token()); String jsonData = getMsgJson(mc) ; logger.info("处理模板消息"+jsonData); strReturnInfo = HttpRequestProxy.doJsonPost(reqUrl, parameters, jsonData); } }else{ logger.info("没有找到对应的配置信息"); } return strReturnInfo; }
Example #24
Source File: JwAccountAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取短链接信息 * @param accessToken * @param longUrl * @return * @throws WexinReqException */ public static String getShortUrl(String accessToken,String longUrl) throws WexinReqException{ ShortUrlCreate uc = new ShortUrlCreate(); uc.setAccess_token(accessToken); uc.setLong_url(longUrl); uc.setAction(SHORT_URL_ACTION); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(uc); Object error = result.get("short_url"); String shortUrl = ""; if (error != null) { shortUrl = result.getString("short_url"); }else{ shortUrl = result.getString(WeiXinConstant.RETURN_ERROR_INFO_MSG); } return shortUrl; }
Example #25
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
public static void main(String[] args){ try { /*WxUpload s = WeixinMediaService.uploadMedia( "kY9Y9rfdcr8AEtYZ9gPaRUjIAuJBvXO5ZOnbv2PYFxox__uSUQcqOnaGYN1xc4N1rI7NDCaPm_0ysFYjRVnPwCJHE7v7uF_l1hI6qi6QBsA", "image","C:/Users/sfli.sir/Desktop/temp/2457331_160355071353_2.jpg");*/ WxDwonload d = JwMediaAPI.downMedia( "kY9Y9rfdcr8AEtYZ9gPaRUjIAuJBvXO5ZOnbv2PYFxox__uSUQcqOnaGYN1xc4N1rI7NDCaPm_0ysFYjRVnPwCJHE7v7uF_l1hI6qi6QBsA", "wBSDL0sz3zqOSGEXG9kIht48V9W7pAQBK50rFKFx1dv6FXsVNROxcxLPMUa9L-yI", "C:/Users/sfli.sir/Desktop/temp/"); System.out.println(d.getFileName()); } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #26
Source File: JwSendMessageAPITest.java From jeewx-api with Apache License 2.0 | 6 votes |
@Test public void testSendMessageToOpenidsWithMedia() { // 多媒体文件按人发送 WxMedia media = new WxMedia(); media.setType("image"); media.setFileName("showqrcode.jpg"); media.setFilePath("F:\\img\\"); try { Wxuser user = new Wxuser(); user.setOpenid(touser); Wxuser[] wxusers = new Wxuser[1]; wxusers[0]=user; service.sendMessageToOpenidsWithMedia(newAccessToken,wxusers, media); } catch (WexinReqException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #27
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取素材总数 * * @param accesstoken * @param accesstoken * * @return WxCountResponse 素材数目返回结果 * @throws WexinReqException */ public static WxCountResponse getMediaCount(String accesstoken) throws WexinReqException { WxCountResponse wxCountResponse = null; if (accesstoken != null) { String requestUrl = material_get_materialcount_url.replace("ACCESS_TOKEN", accesstoken); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST",null); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")) { logger.error("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { wxCountResponse = new WxCountResponse(); wxCountResponse.setImage_count(result.getString("image_count")); wxCountResponse.setNews_count(result.getString("news_count")); wxCountResponse.setVideo_count(result.getString("video_count")); wxCountResponse.setVoice_count(result.getString("voice_count")); } } return wxCountResponse; }
Example #28
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取永久素材 (经测试,该方法调用接口返回时封装实体对象不可用) * * @param accesstoken * @param wxArticles * 图文集合,数量不大于10 * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ public static WxArticlesRespponseByMaterial getArticlesByMaterial(String accesstoken,String mediaId) throws WexinReqException { WxArticlesRespponseByMaterial wxArticlesRespponseByMaterial = null; if (accesstoken != null) { String requestUrl = material_get_material_url.replace("ACCESS_TOKEN", accesstoken); WxArticlesRequestByMaterial wxArticlesRequestByMaterial = new WxArticlesRequestByMaterial(); wxArticlesRequestByMaterial.setMediaId(mediaId); JSONObject obj = JSONObject.fromObject(wxArticlesRequestByMaterial); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")) { logger.error("获得消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获得消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { wxArticlesRespponseByMaterial = (WxArticlesRespponseByMaterial)JSONObject.toBean(result,WxArticlesRespponseByMaterial.class); } } return wxArticlesRespponseByMaterial; }
Example #29
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取素材列表 (经测试,该方法调用接口后json数据转java对象报错) * * @param accesstoken,type,offset,count * @param WxNews * @throws WexinReqException */ public static WxNews queryArticlesByMaterial(String accesstoken,String type,int offset,int count) throws WexinReqException { WxNews wn = null; if (accesstoken != null) { String requestUrl = material_batchget_material_url.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = new JSONObject(); obj.put("type", type); obj.put("offset", offset); obj.put("count", count); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")&&result.get("errcode")!="0") { logger.error("消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("消息消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else{ wn = (WxNews) JSONObject.toBean(result, WxNews.class); } } return wn; }
Example #30
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 上传新增永久图文素材 * * @param accesstoken * @param wxArticles * 图文集合,数量不大于10 * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ public static WxArticlesResponse uploadArticlesByMaterialNews(String accesstoken, List<WxArticle> wxArticles) throws WexinReqException { WxArticlesResponse wxArticlesResponse = null; if (wxArticles.size() == 0) { logger.error("没有上传的图文消息"); } else if (wxArticles.size() > 10) { logger.error("图文消息最多为10个图文"); } else { if (accesstoken != null) { String requestUrl = material_add_news_url.replace("ACCESS_TOKEN", accesstoken); WxArticlesRequest wxArticlesRequest = new WxArticlesRequest(); wxArticlesRequest.setArticles(wxArticles); JSONObject obj = JSONObject.fromObject(wxArticlesRequest); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); if (result.has("errcode")) { logger.error("新增永久图文素材失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); } else { logger.info("=====新增永久图文素材成功=====result:"+result.toString()); wxArticlesResponse = new WxArticlesResponse(); wxArticlesResponse.setMedia_id(result.getString("media_id")); } } } return wxArticlesResponse; }