• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >微信公众号 > 微信公众号开发客服接口实例代码

微信公众号开发客服接口实例代码

作者:匿名 字体:[增加 减小] 来源:互联网

匿名通过本文主要向大家介绍了微信公众号 客服接口等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
微信平台更新之后,发现客服接口不错。研究了下 和大家分享下。

按照官方文档,是向客服接口发送规定的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;
}
 
}

以上的结构就对应

接下来就是对JSON 的数据的创建了

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="";
// 调用接口获取access_token
AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);
if (null != at) {
// 调用接口发送消息
int result = WeixinUtil.Runkf( getkfnews(openid), at.getToken()); // 这个方法会在下面 展示
//int result = WeixinUtil.createMenu(getMenu(),"1832148947");
// 判断菜单创建结果
if (0 == result)
log.info("调用客服信息发送成功!");
else
log.info("客服调用失败,错误码:" + 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("文本内容");
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;
 
}
} 
// 上面的有用到一个调用接口的方法如下:
 
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;
 
 
 
 
 
// 拼装创建的url
 
String url = kf_news_url.replace("ACCESS_TOKEN", token);
 
// 将对象转换成json字符
 
String jsonnews = JSONObject.fromObject(getkfnews).toString();
 
//System.out.println(jsonMenu);
 
// 调用接口创建
 
JSONObject jsonObject = httpRequest(url, "POST", jsonnews);
 
if (null != jsonObject) {
 
if (0 != jsonObject.getInt("errcode")) {
 
result = jsonObject.getInt("errcode");
 
log.error("调用客服接口失败 errcode:{} errmsg:{}");
 
}
 
}
 
 
 
 
 
return result;
 
}

到这里就完成了。可能会比较多。其他的文本的 音乐的 也都是这样的

以上就是微信公众号开发客服接口实例代码的详细内容,更多请关注其它相关文章!

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • asp.net开发微信公众平台(3)微信消息封装及反射赋值
  • 微信开发——通过授权获取用户的基本信息
  • 微信小程序 input输入框控件详解及实例(多种示例)
  • 微信小程序 scroll-view组件实现列表页实例代码
  • 微信公众号中个性化菜单的开发实例
  • 微信开放平台开发——网页微信扫码登录(OAuth2.0)
  • C#微信开发系列-启用开发者模式
  • 关于百度钱包的5篇文章推荐
  • 关于逻辑层的10篇内容推荐
  • 微信开发之上传临时素材介绍

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 详解使用php调用微信接口上传永久素材
    • 教你libco是如何支撑巨大数据信息量的
    • 关于API调用的10篇文章推荐
    • 微信开发接收语音消息的接口与参数
    • 有关微信号的课程推荐10篇
    • 微信公众号开发通过接口删除菜单方法介绍
    • 利用java开发微信实现微信主动推送消息实例
    • 微信开发系列----02:实现POST请求响应
    • 使用web api开发微信公众号调用图灵机器人接口的方法
    • C#开发微信门户及应用-使用地理位置扩展相关应用

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有