欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信公眾號 客服接口的開發(fā)實(shí)例詳解

 更新時(shí)間:2016年09月28日 14:38:57   作者:福建-老妖  
這篇文章主要介紹了微信公眾號 客服接口的開發(fā)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

微信平臺更新之后,發(fā)現(xiàn)客服接口不錯(cuò)。研究了下 和大家分享下。

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

首先先封裝下 JSon 的類:

package com.lwz.wx.bean.kf;

// 這個(gè)是最外層的 也可以說是基類吧、
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;
}
  
}

//這個(gè)類是繼承基類、

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 下同  需要認(rèn)證過的哦
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()); // 這個(gè)方法會在下面 展示
//int result = WeixinUtil.createMenu(getMenu(),"1832148947");
// 判斷菜單創(chuàng)建結(jié)果
if (0 == result)
log.info("調(diào)用客服信息發(fā)送成功!");
else
log.info("客服調(diào)用失敗,錯(cuò)誤碼:" + 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;

}
} 
// 上面的有用到一個(gè)調(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;

}



到這里就完成了??赡軙容^多。其他的文本的 音樂的 也都是這樣的

希望能幫助大家學(xué)習(xí)參考此部分內(nèi)容,謝謝大家對本站的支持!

相關(guān)文章

  • JS前端性能優(yōu)化解決內(nèi)存泄漏頁面崩潰

    JS前端性能優(yōu)化解決內(nèi)存泄漏頁面崩潰

    這篇文章主要為大家介紹了JS前端性能優(yōu)化解決內(nèi)存泄漏頁面崩潰示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 前端算法leetcode109題解有序鏈表轉(zhuǎn)換二叉搜索樹

    前端算法leetcode109題解有序鏈表轉(zhuǎn)換二叉搜索樹

    這篇文章主要為大家介紹了前端算法leetcode109題解有序鏈表轉(zhuǎn)換二叉搜索樹示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • 前端使用koa實(shí)現(xiàn)大文件分片上傳

    前端使用koa實(shí)現(xiàn)大文件分片上傳

    這篇文章主要為大家介紹了前端使用koa實(shí)現(xiàn)大文件分片上傳示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • 前端通過JavaScript創(chuàng)建修改CAD圖形詳情

    前端通過JavaScript創(chuàng)建修改CAD圖形詳情

    這篇文章介紹JavaScript創(chuàng)建修改CAD圖形,創(chuàng)建修改CAD圖形,一般是基于AutoCAD進(jìn)行二次開發(fā),ObjectARX是AutoDesk公司針對AutoCAD平臺上的二次開發(fā)而推出的一個(gè)開發(fā)軟件包,它提供了以C++為基礎(chǔ)的面向?qū)ο蟮拈_發(fā)環(huán)境及應(yīng)用程序接口,能真正快速的訪問AutoCAD圖形數(shù)據(jù)庫
    2021-10-10
  • 使用pnpm包管理器替代npm及yarn的命令示例

    使用pnpm包管理器替代npm及yarn的命令示例

    這篇文章主要為大家介紹了使用pnpm包管理器替代npm及yarn的命令示例使用方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • JS算法題解搜索插入位置方法示例

    JS算法題解搜索插入位置方法示例

    這篇文章主要為大家介紹了JS算法題解搜索插入位置方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • Web?Animations?API實(shí)現(xiàn)一個(gè)精確計(jì)時(shí)的時(shí)鐘示例

    Web?Animations?API實(shí)現(xiàn)一個(gè)精確計(jì)時(shí)的時(shí)鐘示例

    這篇文章主要為大家介紹了Web?Animations?API實(shí)現(xiàn)一個(gè)精確計(jì)時(shí)的時(shí)鐘示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 微信小程序Redux綁定實(shí)例詳解

    微信小程序Redux綁定實(shí)例詳解

    這篇文章主要介紹了微信小程序Redux綁定實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • JavaScript事件委托原理

    JavaScript事件委托原理

    這篇文章主要介紹了JavaScript事件委托原理,?事件委托也稱為事件代理。就是利用事件冒泡,把子元素的事件都綁定到父元素上。如果子元素阻止了事件冒泡,那么委托就無法實(shí)現(xiàn),下面我們一起來學(xué)習(xí)文章的具體詳細(xì)內(nèi)容吧
    2021-12-12
  • vscode工具函數(shù)once使用示例深入剖析

    vscode工具函數(shù)once使用示例深入剖析

    這篇文章主要為大家介紹了vscode工具函數(shù)once使用示例深入剖析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03

最新評論