Package Com.wanhua.weixin.model;
Import Java.util.HashMap;
Import Java.util.Map;
Import ORACLE.NET.ASO.A;
Import Org.json.JSONObject;
Import Org.junit.Test;
Import Play.cache.Cache;
Import Com.alibaba.fastjson.JSON;
Import Com.wanhua.weixin.util.WXConst;
Import Com.wanhua.weixin.util.WXHttpUtil;
/**
* Send customer service text message
*
* @author W_xfpenga
*
* 2014-11-28
*
*/
public class Customreplymsg {
General User OpenID
Public String Touser;
Message type, text
Public String Msgtype;
Text message Content
Public map<string, object> text;
/**
* Initialize system messages sent by default
*
* @param fromusername
* General User OpenID
* @param msgtype
* Message type, text
* @param content
* Text message Content
* @throws Exception
*/
public static void Initsendmsg (String fromusername, String msgtype, String content) throws Exception {
The credential that gets to
String Access_token = Accesstoken.getaccesstoken ();
Request Address
String Requesturl = Wxconst.custom_url + Access_token;
map<string, object> text = new hashmap<string, object> ();
Text.put ("content", content);
Instantiating a Customreplymsg object
Customreplymsg customrelymsg = new Customreplymsg ();
Customrelymsg.touser = Fromusername;
Customrelymsg.msgtype = Msgtype;
Customrelymsg.text = text;
Output parameters
String outputstr = json.tojsonstring (customrelymsg);
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 Message success!!!" ");
} else {
Request failed return prompt information
System.out.println ("Failed to send Message!!! ");
}
}
}
Send customer service text message