欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

微信公眾號開發(fā)客服接口的示例分析

這篇文章主要為大家展示了“微信公眾號開發(fā)客服接口的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信公眾號開發(fā)客服接口的示例分析”這篇文章吧。

創(chuàng)新互聯(lián)建站服務(wù)項目包括溧陽網(wǎng)站建設(shè)、溧陽網(wǎng)站制作、溧陽網(wǎng)頁制作以及溧陽網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,溧陽網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到溧陽省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

微信平臺更新之后,發(fā)現(xiàn)客服接口不錯。

按照官方文檔,是向客服接口發(fā)送規(guī)定的JSon 就可以了。

首先先封裝下 JSon 的類:

package com.lwz.wx.bean.kf;
 
// 這個是最外層的 也可以說是基類吧、
public class Basebean {
private String touser;
private String msgtype;
 
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
   
}
//這個類是繼承基類、
 
package com.lwz.wx.bean.kf;
public class BaseNews extends Basebean{
  private Kfnews news;
public Kfnews getNews() {
return news;
}
public void setNews(Kfnews news) {
this.news = news;
}
 
}
//
package com.lwz.wx.bean.kf;
import java.util.List;
public class Kfnews {
private List<articles> articles;
public List<articles> getArticles() {
return articles;
}
public void setArticles(List<articles> articles) {
this.articles = articles;
}
}
//
package com.lwz.wx.bean.kf;
 
 
public class articles {
private String title;
  private String description;
  private String url;
  private String picurl;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getPicurl() {
return picurl;
}
public void setPicurl(String picurl) {
this.picurl = picurl;
}
 
}

以上的結(jié)構(gòu)就對應(yīng)

接下來就是對JSON 的數(shù)據(jù)的創(chuàng)建了

package com.lwz.wx.main;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import net.sf.json.JSONObject;
import com.lwz.wx.bean.AccessToken;
import com.lwz.wx.bean.Articles;
import com.lwz.wx.bean.kf.BaseNews;
import com.lwz.wx.bean.kf.BaseText;
import com.lwz.wx.bean.kf.Basebean;
import com.lwz.wx.bean.kf.Kfnews;
import com.lwz.wx.bean.kf.articles;
import com.lwz.wx.bean.kf.text;
import com.lwz.wx.util.WeixinUtil;
 
 
 
 
public class KfManager {
private final static Logger log = Logger.getLogger(Basebean.class);
   public static void Gotokf(String openid){
     String appId =""; //填上自己的APPID 下同  需要認證過的哦
String appSecret="";
// 調(diào)用接口獲取access_token
AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);
if (null != at) {
// 調(diào)用接口發(fā)送消息
int result = WeixinUtil.Runkf( getkfnews(openid), at.getToken()); // 這個方法會在下面 展示
//int result = WeixinUtil.createMenu(getMenu(),"1832148947");
// 判斷菜單創(chuàng)建結(jié)果
if (0 == result)
log.info("調(diào)用客服信息發(fā)送成功!");
else
log.info("客服調(diào)用失敗,錯誤碼:" + result);
}
  }
private static BaseNews getkfnews(String openid) {
articles art1=new articles();
art1.setDescription("1");
art1.setPicurl("http://www.baidu.com");
art1.setTitle("測試1");
art1.setUrl("http://www.baidu.com");
 
articles art2=new articles();
art2.setDescription("1");
art2.setPicurl("http://www.baidu.com");
art2.setTitle("測試1");
art2.setUrl("http://www.baidu.com");
List<articles> list = new ArrayList<articles>();
Kfnews news=new Kfnews();
list.add(art1);
list.add(art2);
news.setArticles(list);
 
BaseNews kfbean=new BaseNews();
kfbean.setMsgtype("news");
kfbean.setTouser(openid);
kfbean.setNews(news);
String jsonkfbean = JSONObject.fromObject(kfbean).toString();
System.out.println(jsonkfbean);
return kfbean;
 
}
 
private static BaseText getkftext(String openid) {
  text text=new text();
text.setContent("文本內(nèi)容");
BaseText textbean=new BaseText();
textbean.setMsgtype("text");
textbean.setTouser(openid);
textbean.setText(text);
String jsonkfbean = JSONObject.fromObject(textbean).toString();
System.out.println(jsonkfbean);
return textbean;
 
}
} 
// 上面的有用到一個調(diào)用接口的方法如下:
 
public static String kf_news_url= "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
 
public static int Runkf(Basebean getkfnews, String token) {
 
int result = 0;
 
 
 
 
 
// 拼裝創(chuàng)建的url
 
String url = kf_news_url.replace("ACCESS_TOKEN", token);
 
// 將對象轉(zhuǎn)換成json字符
 
String jsonnews = JSONObject.fromObject(getkfnews).toString();
 
//System.out.println(jsonMenu);
 
// 調(diào)用接口創(chuàng)建
 
JSONObject jsonObject = httpRequest(url, "POST", jsonnews);
 
if (null != jsonObject) {
 
if (0 != jsonObject.getInt("errcode")) {
 
result = jsonObject.getInt("errcode");
 
log.error("調(diào)用客服接口失敗 errcode:{} errmsg:{}");
 
}
 
}
 
 
 
 
 
return result;
 
}

以上是“微信公眾號開發(fā)客服接口的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文標(biāo)題:微信公眾號開發(fā)客服接口的示例分析
網(wǎng)頁URL:http://chinadenli.net/article18/pdsedp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、域名注冊、商城網(wǎng)站、自適應(yīng)網(wǎng)站、網(wǎng)站改版、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司