Package Com.wanhua.weixin.model;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Org.json.JSONArray;
Import org.json.JSONException;
Import Org.json.JSONObject;
Import Org.junit.Test;
Import Play.cache.Cache;
Import Play.i18n.Messages;
Import Com.alibaba.fastjson.JSON;
Import Com.wanhua.util.Const;
Import Com.wanhua.weixin.util.WXConst;
Import Com.wanhua.weixin.util.WXHttpUtil;
/**
* Mass advanced mass message according to the OpenID list
*
* @author W_xfpenga
*
* 2014-11-27
*/
public class Advanceinterfacemsg {
Fill in the text message recipient, a list of OpenID, OpenID minimum 1, up to 10,000
Public list<string> Touser;
Mpnews for mass text messages
Public map<string, object> mpnews;
Mass message type, text message for mpnews, texts message for voice, audio for music, image for video
Public String Msgtype;
/**
* Send high-level mass message according to the advanced Mass interface of the OpenID list mass
*
* @param wxmsgxml
*/
public static int Sendmsgnewsbyopenid (list<string> touser, String media_id) {
The credential that gets to
String Access_token = Accesstoken.getaccesstoken ();
Request Address
String Requesturl = Wxconst.advance_interface_url + Access_token;
The ID of the uploaded file
map<string, object> mpnews = new hashmap<string, object> ();
Mpnews.put ("media_id", media_id);
Instantiate an advanced bulk Message object
Advanceinterfacemsg advanceinterfacemsg = new Advanceinterfacemsg ();
Advanceinterfacemsg.touser = Touser;
Advanceinterfacemsg.mpnews = Mpnews;
Advanceinterfacemsg.msgtype = "Mpnews";
Request OUTPUT parameters
String outputstr = json.tojsonstring (advanceinterfacemsg);
try {
The result of the request returned
String result = Wxhttputil.msghttpsrequest (Requesturl, "POST", outputstr);
Convert returned results to JSON formatted data
Jsonobject resultobj = new Jsonobject (result);
The status code of the returned result
int code = resultobj.getint ("Errcode");
if (code = = 0) {
Request successfully returned prompt message
SYSTEM.OUT.PRINTLN ("Send advanced Mass message success" + result);
return 0;
} else {
Request failed return prompt information
SYSTEM.OUT.PRINTLN ("Send advanced mass message failed" + result);
return 1;
}
} catch (Exception e) {
E.printstacktrace ();
return 1;
}
}
/**
* According to delete advanced mass message
*
* @param msg_id
*/
public static void Deleteadvancemsg (String msg_id) {
Jsonobject jsonobject = new Jsonobject ();
try {
Jsonobject.put ("msg_id", msg_id);
The credential that gets to
String Access_token = Accesstoken.getaccesstoken ();
Request Address
String Requesturl = Wxconst.delete_advance_url + Access_token;
Request parameters
String outputstr = jsonobject.tostring ();
try {
The result of the request returned
String result = Wxhttputil.msghttpsrequest (Requesturl, "POST", outputstr);
Convert returned results to JSON formatted data
Jsonobject resultobj = new Jsonobject (result);
The status code of the returned result
int code = resultobj.getint ("Errcode");
if (code = = 0) {
Request successfully returned prompt message
System.out.println (Messages.get ("advance_interface_delete_message_success") + result);
} else {
Request failed return prompt information
System.out.println (Messages.get ("advance_interface_delete_message_fail") + result);
}
} catch (Exception e) {
E.printstacktrace ();
}
} catch (Jsonexception E1) {
TODO auto-generated Catch block
E1.printstacktrace ();
}
}
}
Mass advanced mass message based on OpenID list