1. 程式人生 > >java 微信傳送客服訊息

java 微信傳送客服訊息

    public static boolean sendCustomMessage(String accessToken, String jsonMsg){  
            logger.info("訊息內容:{"+jsonMsg+"}");  
            boolean result = false;  
            //請求地址  
            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";  
            requestUrl = requestUrl.replace("ACCESS_TOKEN", accessToken);  
            //傳送客服訊息  
            JSONObject jsonObject = WeixinUtil.httpRequest(requestUrl, "POST", jsonMsg);  
            if(null != jsonObject){  
                int errorCode = jsonObject.getInt("errcode");  
                String errorMsg = jsonObject.getString("errmsg");  
                if(0 == errorCode){  
                    result = true;  
                    logger.info("客服訊息傳送成功errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}");  
                    System.out.println("客服訊息傳送成功errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}");  
                }else{  
                    logger.info("客服訊息傳送失敗errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}");  
                    System.out.println("客服訊息傳送失敗errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}");  
                    if(errorCode == 40001 || errorCode == 42001 ){  
                        System.out.println("12321");  
                        new Thread(new TokenThreadNew()).start();  
                    }  
                }  
            }  
            return result;  
        }