WeChat 자료 관리 및 대량 게시가 Java에 친숙하지 않다고 다시 불평하고 싶습니다.이 기사는 이전 기사 및 공식 문서와 결합되어야합니다.
질량을 송신하는 테스트 번호를 디버깅 할 때, 대량 전송 메시지를 성공적으로 조립할 수 있는지 확인하면 될 뿐이며 WeChat이 아직이 기능을 열지 않았기 때문에 결과를 볼 필요가 없습니다 (어쨌든 전송되지 않음).
1. 질량 진술
공개 플랫폼 웹 사이트에서 가입 계정에는 하루에 1 개의 대량 발송 허가가 제공되며 서비스 계정에는 월에 4 개의 대량 발송 권한이 제공됩니다 (자연 월).
1. 인증 된 가입 계정의 경우 질량 전송 인터페이스를 하루에 한 번 성공적으로 호출 할 수 있습니다. 이 질량 보내기는 모든 사용자 또는 특정 태그에 전송하도록 선택할 수 있습니다.
2. 고급 질량 전송 인터페이스를 사용하는 개발자의 일일 통화는 인증 서비스 계정의 경우 100 배로 제한되지만 사용자는 한 달에 4 개의 메시지 만받을 수 있습니다. 공개 플랫폼 웹 사이트에서 또는 대량 전송 인터페이스를 사용하든 사용자는 한 달에 4 개의 메시지 만받을 수 있습니다. 4 개 이상의 대량 발송은 사용자에게 보내지 못할 것입니다.
3. 개발자는 반복적 인 푸시를 피하기 위해 ClientMSGID를 적극적으로 설정할 수 있습니다.
4. 질량 인터페이스는 분당 60 개의 요청을 제한하며 한도를 초과하는 요청이 거부됩니다.
5. 대량 기사에 게시 된 텍스트 및 문자 메시지 링크에 자신의 계정 및 기타 공개 계정을 삽입하는 기능.
2. 문자 메시지 보내는 대량 발송 과정
1. 먼저 업로드 이미지 및 문자 메시지에서 이미지 인터페이스를 사용하여 성공적으로 업로드하고 이미지 URL을 얻습니다. URL 메소드를 얻으려면 이미지 및 문자 메시지를 업로드하려면 이전 텍스트를 참조하십시오.
2. 그래픽 및 문자 메시지 자료를 업로드 할 때 이전 단계에서 얻은 이미지 URL을 사용하십시오.
3. 텍스트 및 문자 메시지를 보내려면 사용자 태그로 대량 전송 또는 OpenID 목록의 질량 전송을 사용하십시오. 대량 보내기 동안 WeChat은 원래 검증을 수행하고 대량 발송 작업 결과를 반환합니다.
4. 위의 프로세스에서 필요한 경우 그래픽 및 문자 메시지를 미리보기, 질량 전송 상태를 쿼리하거나 질량 보내기 메시지 등을 삭제할 수도 있습니다.
3. 질량 사진 및 텍스트와 같은 다른 메시지 유형을 보내는 과정
1. 대량 문자 메시지 인 경우 다음 인터페이스 지침에 따라 직접 보내십시오.
2. 대량 사진, 비디오 등과 같은 메시지를 보내는 경우 자료 관리 인터페이스를 통해 미디어를 미리 준비해야합니다.
IV. IS_TO_ALL 설명
모든 사용자에게 전송할지 여부를 설정하고 값은 true 또는 false이며 True를 선택하고 메시지가 그룹의 모든 사용자에게 전송되고 Tag_id에 따라 지정된 그룹의 사용자에게 보내려면 False를 선택합니다.
5. 두 가지 유형의 질량 보내기 방법
태그에 따라 질량 보내기, 구독 번호 및 서비스 번호는 인증해야합니다.
인터페이스 : https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=access_token
OpenID 목록에 따른 질량 발송은 인증 된 서비스 번호에만 적용됩니다.
인터페이스 : https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=access_token
게시물 데이터는 그래픽 메시지, 텍스트, 음성/오디오, 사진, 비디오 및 카드 쿠폰 메시지 일 수 있습니다 (Media_id가 사용되는 모든 장소에서는 이제 자료 관리에서 영구 자료 미디어를 사용할 수 있습니다).
1. 문자 메시지의 게시물 데이터의 Media_id는 업로드 문자 메시지 자료 인터페이스 업로드를 통해 얻어야합니다 (https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=access_token)
이는 재료 관리의 새로운 영구 그래픽 자료 인터페이스의 게시물 데이터와 동일하지만 인터페이스는 다르며 반환 된 JSON에는 추가 유형이 있으며 create_at가 있습니다. 이전 기사에서 영구 그래픽 자료를 추가하는 방법을 참조하십시오.
2. Media_ID 음성/오디오 및 사진 게시물 데이터는 멀티미디어 파일 인터페이스를 업로드하고 다운로드하여 얻어야합니다. 이전 기사의 새로운 임시/영구 자료 방법을 참조하십시오.
3. 비디오 게시물 데이터의 Media_id가 가장 번거 롭습니다. 먼저 업로드를 통해 Media_ID를 얻고 멀티미디어 파일 인터페이스를 다운로드해야합니다 (테스트 후 영구적 인 다음 단계 오류 프롬프트는 잘못된 Media_ID입니다). 이것은 대량 보내기에 필요한 Media_id입니다.
6. 벌크 샘플 컨트롤러
@requestmapping ( "/sendByopenid") public MassMsgresult sendByopenid ()는 예외를 던지려고 {// OpenID 목록에 따라 질량 문자 메시지를 보내십시오. String madiapath1 = "c : /users/phil/pictures/image/8538572f61d7a94cf0b9fe0f290cdb28.jpg"; uploadmediasresult result1 = httprequtil.uploadtempmedia ( "phil_token", "image", mediapath1); 문자열 mediapath2 = "c : /users/phil/pictures/image/685977abgw1f8xqp46dgyj20qo0zktfi.jpg"; uploadmediasresult result2 = httprequtil.uploadtempmedia ( "phil_token", "image", mediapath2); 목록 <uploadnewsmedia> array = new arraylist <> (); uploadnewsmedia entity1 = new uploadNewSmedia (); Entity1.SetAuthor ( "Phil"); ENTITY1. SETCONTENT ( "만 경험만을 이해할 수 있고, 그것을 소중히하는 방법을 알고, 그것을 이해하는 방법 만 알고, 당신의 인생에서 항상 당신을 가장 달콤하게 웃게하는 사람이있을 것이며, 항상 당신을 가장 깊이 느끼고, 잊고, 자신을 친절하게 대하는 사람이 항상있을 것입니다"); Entity1.SetContent_Source_url ( "http://blog.csdn.net/phil_jing"); // entity1.setDigest ( "다이제스트"); Entity1.setshow_conver_pic (1); entity1.setThumb_media_id (result1.getmedia_id ()); 엔티티 1. 세트 타이틀 ( "소울 치킨 스프"); Array.add (entity1); uploadnewsmedia entity2 = new uploadNewSmedia (); Entity2.SetAuthor ( "Phil"); Entity2.SetContent ( "행복은 무엇입니까? 행복은 행복한 심리적 상태와 자신의 느낌입니다. 항상 자신을 행복하게 만들 수있는 사람들만이 가장 행복한 사람들입니다. 가장 행복한 사람들은 가장 행복한 사람들입니다. 종종 웃는 사람들은 가장 행복한 사람들입니다."); Entity2.SetContent_Source_url ( "http://www.qq.com"); // entity2.SetDigest ( "다이제스트"); entity2.setshow_conver_pic (0); entity2.setThumb_media_id (result2.getmedia_id ()); Entity2.SetTitle ( "클래식 인용문"); Array.add (entity2); uploadmediasresult ur = httprequtil.uploadnewsmedia ( "phil_token", array); list <string> openIds = new ArrayList <> (); OpenIds.add ( "ovhq5v9-zshucax_ntcqwip-sbcg"); OpenIds.add ( "ovhq5v6cw3inkwuscl3olodif0cc"); MassMsgresult result_news = wechatmsgservice.sendmpnewstoopenid ( "phil_token", openids, ur.getmedia_id ()); logger.debug ( "OpenID msg {}", result_news.getErrmsg ()); // OpenID 목록 MassMsgresult result_text = wechatmsgservice.sendtexttoopenid ( "phil_token", openids, "행복은 무엇입니까? logger.debug ( "OpenID msg {}", result_text.geterRmsg ()); 널 리턴; }7. 사용 된 클래스와 방법 중 일부
질량 보내기 방법
/ *** 태그를 기반으로 문자 메시지 보내기* @param accesstoken 승인 된 토큰* @param 엔티티 그래픽 메시지 객체* @return*/ public massmsgresult sendTextTotag (String AccessToken, Int Tagid, String Content) {MassMsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> FilterParams = new Hashmap <> (); filterparams.put ( "is_to_all", false); filterparams.put ( "tag_id", tagid); Map <String, Object> TextParams = New Hashmap <> (); TextParams.put ( "content", 컨텐츠); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "필터", 필터 파람); dataparams.put ( "text", textParams); dataparams.put ( "msgtype", "text"); 문자열 data = jsonutil.tojsonstring (dataparams); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_all_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * 태그를 기반으로하는 대량 문자 메시지 * @Param AccessToken Token * @param tagid tag * @param mediaid uploadmedia method gets * @return * / public massmsgresult sendmpnewstotag (String accesstoken, int tagid, string mediaid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> FilterParams = new Hashmap <> (); filterparams.put ( "is_to_all", false); filterparams.put ( "tag_id", tagid); map <string, object> mpnewsparams = new Hashmap <> (); mpnewsparams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "필터", 필터 파람); dataparams.put ( "mpnews", mpnewsparams); dataparams.put ( "msgtype", "mpnews"); dataparams.put ( "send_ignore_reprint", 0); // String data = jsonutil.tojsonstring (dataparams); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_all_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * 태그를 기반으로 한 벌크 이미지 * @param accesstoken 승인 된 토큰 * @param tagid tag * @param mediaid uploadmedia method get * @return * / public massmsgresult sendimagetotag (String accesstoken, int tagid, string mediaid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> FilterParams = new Hashmap <> (); filterparams.put ( "is_to_all", false); filterparams.put ( "tag_id", tagid); Map <String, Object> ImageParams = New Hashmap <> (); ImageParams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "필터", 필터 파람); dataparams.put ( "image", imageparams); dataparams.put ( "msgtype", "image"); 문자열 data = jsonutil.tojsonstring (dataparams); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_all_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; }/** * 태그에 따른 대량 음성/오디오 * @param accesstoken 승인 토큰 * @param tagid tag * @param mediaid uploadmedia method get * @return */public massmsgresult sendvoicetotag (String accesstoken, int tagid, string mediaid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> FilterParams = new Hashmap <> (); filterparams.put ( "is_to_all", false); filterparams.put ( "tag_id", tagid); Map <String, Object> Voyparams = New Hashmap <> (); VoiceParams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "필터", 필터 파람); Dataparams.put ( "Voice", VoiceParams); dataparams.put ( "msgtype", "음성"); 문자열 data = jsonutil.tojsonstring (dataparams); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_all_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * 태그를 기반으로 한 벌크 비디오 * @param accesstoken 승인 된 토큰 * @param tagid tag * @param mediaid uploadmedia method get * @return * / public massmsgresult sendvideototag (String accesstoken, int tagid, string mediaid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> FilterParams = new Hashmap <> (); filterparams.put ( "is_to_all", false); filterparams.put ( "tag_id", tagid); Map <string, object> mpvideoparams = new Hashmap <> (); mpvideoparams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "필터", 필터 파람); dataparams.put ( "mpvideo", mpvideoparams); dataparams.put ( "msgtype", "mpvideo"); 문자열 data = jsonutil.tojsonstring (dataparams); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_all_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * 태그를 기반으로 한 벌크 카드 쿠폰 * @param accesstoken 승인 된 토큰 * @param tagid tag * @param card_id * @return * / public massmsgresult sendwxcardtotag (String accesstoken, int tagid, string cardid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> FilterParams = new Hashmap <> (); filterparams.put ( "is_to_all", false); filterparams.put ( "tag_id", tagid); map <string, object> wxcardparams = new Hashmap <> (); wxcardparams.put ( "card_id", cardid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "필터", 필터 파람); dataparams.put ( "wxcard", wxcardparams); dataparams.put ( "msgtype", "wxcard"); 문자열 data = jsonutil.tojsonstring (dataparams); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_all_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * OpenID를 기반으로 대량 문자 메시지 보내기 * @Param AccessToken 승인 된 토큰 * @param tagid tag * @param mediaid uploadmedia method get * @return * / public massmsgresult sendmpnewstoopenid (list <string> openids, string mediaid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <String, Object> mpnewsparams = new Hashmap <> (); mpnewsparams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "touser", openids); dataparams.put ( "mpnews", mpnewsparams); dataparams.put ( "msgtype", "mpnews"); dataparams.put ( "send_ignore_reprint", 0); 문자열 data = jsonutil.tojsonstring (dataparams); String JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * OpenID를 기반으로 한 대량 문자 메시지 * @param accesstoken 권한 부여 토큰 * @param openids olopelid * @param content * @return * / public massMsgresult sendTextToopenid (문자열 accestToken, list <string> openID, 문자열 내용) {massMsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> textParams = new Hashmap <> (); TextParams.put ( "content", 컨텐츠); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "touser", openids); dataparams.put ( "text", textParams); dataparams.put ( "msgtype", "text"); 문자열 data = jsonutil.tojsonstring (dataparams); System.out.println (데이터); String JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * OpenID를 기반으로 대량 음성 메시지 보내기 * @param accesstoken 권한 부여 토큰 * @param openids openid * @param mediaid * @return * / public massMsgresult sendVocietOpenid (문자열 accessToken, list <string> openID, String mediaid) {MassMSTGresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 개체> VoyParams = new Hashmap <> (); VoiceParams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "touser", openids); Dataparams.put ( "Voice", VoiceParams); dataparams.put ( "msgtype", "음성"); 문자열 data = jsonutil.tojsonstring (dataparams); System.out.println (데이터); String JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * OpenID를 기반으로 한 대량 이미지 메시지 * @Param AccessToken 승인 된 토큰 * @param openIds openID * @param mediaid * @return * / public massMsgresult sendImagetoopenid (String accestToken, list <string> openID, String mediaid) {massMSTgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 객체> imageParams = new Hashmap <> (); ImageParams.put ( "media_id", mediaid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "touser", openids); dataparams.put ( "image", imageparams); dataparams.put ( "msgtype", "image"); 문자열 data = jsonutil.tojsonstring (dataparams); System.out.println (데이터); String JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * OpenID를 기반으로 한 대량 비디오 메시지 * @Param AccessToken 승인 된 토큰 * @param openIds OpenID * @Param MPVIDEOMEDIA UPLOADMEDIAVIDEO METHODS 획득 미디어 * @return * / public MassMsgresult SendVideOtoopenid (문자열 accesstoken, list <string> openID, mpvideomedia mpvideomedia) {massms = NULLGGREST (MPVIDEOMEDIA); treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "touser", openids); dataparams.put ( "mpvideo", mpvideomedia); dataparams.put ( "msgtype", "mpvideo"); 문자열 data = jsonutil.tojsonstring (dataparams); System.out.println (데이터); String JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; } / ** * OpenID를 기반으로 한 질량 카드 쿠폰 메시지 * @param accesstoken 권한 부여 토큰 * @param openids openid * @param mediaid * @return * / public massmsgresult sendwxcardtoopenid (문자열 accesstoken, list <string> openids, String cardid) {massmsgresult result = null; treemap <string, String> params = new Treemap <> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 맵 <문자열, 개체> wxcardparams = new Hashmap <> (); wxcardparams.put ( "card_id", cardid); Treemap <String, Object> Dataparams = New Treemap <> (); dataparams.put ( "touser", openids); dataparams.put ( "wxcard", wxcardparams); dataparams.put ( "msgtype", "wxcard"); 문자열 data = jsonutil.tojsonstring (dataparams); String JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.send_mass_message_url, params, data); try {result = jsonutil.fromjsonstring (json, massmsgresult.class); } catch (예외 e) {e.printstacktrace (); } 반환 결과; }비디오 게시물 데이터 빈
/ ** * 비디오 게시물 데이터 bean * @Author Phil * @date 2017 년 9 월 20 일 * */ public class mpvideomedia {private String media_id; 개인 문자열 제목; 개인 문자열 설명; }대량 비디오 게시물에서 Media_id를 얻으십시오
/ ** * 질량 비디오의 게시물에서 미디어 _id를 얻습니다 * @param accesstoken * @param uploadvideo * @return */ public static uploadmediasresult uploadMediaVideo (String AccessToken, Mpvideomedia mpvideomedia) {uploadMediasresult result = null; treemap <string, String> params = new Treemap <String, String> (); params.put ( "access_token", accesstoken); // 제출 된 매개 변수 문자열 data = jsonutil.tojsonstring (mpvideomedia); 문자열 JSON = httprequtil.httpsdefaultexecute (SystemConfig.post_method, wechatconfig.upload_video_media_url, params, data); 결과 = jsonutil.fromjsonstring (json, uploadmediasresult.class); 반환 결과; }질량에 의해 반환 된 결과
package com.phil.wechat.msg.model.resp; import com.phil.wechat.base.result.resultstate; / *** 대량 메시지에 의해 반환 된 결과* OpenID 목록에 따라 대량 보내기* @Author Phil* @date 2017 년 7 월 2 일*/ public class massMsgresult 확장 결과 {private String type; // 미디어 파일 유형은 이미지 (이미지), 음성 (음성), 비디오 (비디오) 및 썸네일 (썸네일)이 포함되며, 횟수는 뉴스, 즉 그래픽 및 문자 메시지 개인 문자열 msg_id; 개인 문자열 msg_data_id; }구성 클래스
// Group 공개 정적 최종 문자열로 질량을 전송합니다. send_all_mass_message_url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; // OpenID에 따라 질량 메시지를 전합니다 (최소 2 개의 OpenID, 최대 10,000 10,000) 공개 정적 최종 문자열 send_mass_message_url = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; // 그래픽 및 문자 메시지 자료를 업로드하고 공개 정적 최종 문자열 업로드 upload_news_media_url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; // mass video post에서 "https://api.weixin.qq.com/cgi-bin/media/uploadvideo";
소스 코드와 관련하여 도움이되기를 바랍니다
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.