微信公众号客服消息提醒

Posted 3b2414

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信公众号客服消息提醒相关的知识,希望对你有一定的参考价值。

微信客服消息提醒:
    public static void Test(String openid) throws Exception{   
        String token = getWeiXinAccessToken.getToken();
        String strJson = "{"touser" :""+openid+"",";
        strJson += ""msgtype":"text",";
        strJson += ""text":{";
        strJson += ""content":"这里写你要提示的信息!"";
        strJson += "}}";
        String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?&body=0&access_token=" + token;
        post(url, strJson);
    }

    public static void post(String url, String json){
        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(url);
        try{
            StringEntity s = new StringEntity(json.toString(),"UTF-8");
            //s.setContentEncoding("UTF-8");
            s.setContentType("application/json");
            post.setEntity(s);
            HttpResponse res = client.execute(post);
            if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                HttpEntity entity = res.getEntity();
                System.out.println(EntityUtils.toString(entity, "utf-8"));
            }
        }catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

 public class getWeiXinAccessToken {
      public static  String getToken() {  
             String getResponse="";
             String appid= "公众号AppID";
             String secret= "公众号secret";
             try{  
                    String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;  
                       HttpClient httpClient = new HttpClient();  
                    GetMethod getMethod = new GetMethod(url);  
                  int execute = httpClient.executeMethod(getMethod);  
                  System.out.println("execute:"+execute);  
                    getResponse = getMethod.getResponseBodyAsString(); 
            } catch (IOException e){  
                e.printStackTrace();  
            }  
            System.out.println(getResponse);  
            JSONObject json=JSONObject.fromObject(getResponse);      
            return json.getString("access_token");  
       }  
    
    } 















































以上是关于微信公众号客服消息提醒的主要内容,如果未能解决你的问题,请参考以下文章

公众号怎么接入客服功能?

微信公众号和公众号客服系统有什么区别,要怎么绑定?

微信公众号客服系统(助手)怎么样?

微信公众号营销用鱼塘微营销系统怎么样?

如何使用微信公众平台小程序

如何获取微信公众号的URL地址 用于HTML网页的