Send customer service text message

Source: Internet
Author: User
Tags openid

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.