栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【微信开发】9、SpringBoot整合WxJava实现多客服管理

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【微信开发】9、SpringBoot整合WxJava实现多客服管理

当用户和公众号产生特定动作的交互时(具体动作列表请见下方说明),微信将会把消息数据推送给开发者,开发者可以在一段时间内(目前为48小时,2021年6月1日后启用新规则,查看公告)调用客服接口,通过POST一个JSON数据包来发送消息给普通用户。此接口主要用于客服等有人工消息处理环节的功能,方便开发者为用户提供更加优质的服务。

目前允许的动作列表如下:

1、用户发送信息
2、点击自定义菜单(仅有点击推事件、扫码推事件、扫码推事件且弹出“消息接收中”提示框这3种菜单类型是会触发客服接口的)
3、关注公众号
4、扫描二维码
5、支付成功

1、官方文档:
https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html
2、整合WxJava客服管理
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("wx/mp/kefu")
public class WxMpKefuController {

    @Autowired
    private WxMpService wxMpService;

    
    @GetMapping("listKf")
    public String listKf() throws WxErrorException {
        WxMpKfList wxMpKfList = wxMpService.getKefuService().kfList();
        return wxMpKfList.toString();
    }

    
    @GetMapping("addKf")
    public String addKf() throws WxErrorException {
        // 客服账号、客服名称
        WxMpKfAccountRequest wxMpKfAccountRequest = new WxMpKfAccountRequest("xxxx@gh_xxxxxxxxxxx", "Asurplus", "");
        boolean b = wxMpService.getKefuService().kfAccountAdd(wxMpKfAccountRequest);
        return b ? "添加成功" : "添加失败";
    }

    
    @GetMapping("inviteBinding")
    public String inviteBinding() throws WxErrorException {
        // 客服账号、客服微信号
        WxMpKfAccountRequest wxMpKfAccountRequest = new WxMpKfAccountRequest("xxxx@gh_xxxxxxxxxxx", "", "xxxxxxxxx");
        boolean b = wxMpService.getKefuService().kfAccountInviteWorker(wxMpKfAccountRequest);
        return b ? "发送成功" : "发送失败";
    }

    
    @GetMapping("deleteKf")
    public String deleteKf() throws WxErrorException {
        // 客服账号、客服名称
        boolean b = wxMpService.getKefuService().kfAccountDel("xxxx@gh_xxxxxxxxxxx");
        return b ? "删除成功" : "删除失败";
    }
}

注意:

完整客服帐号,格式为:帐号前缀@公众号微信号,测试号的微信号在这里:

3、测试客服管理

1、查询客服列表

localhost:8080/wx/mp/kefu/listKf

查询结果:

此时我们还没有客服

2、添加一个客服

localhost:8080/wx/mp/kefu/addKf

添加结果:

此时我们再次查询客服列表:

此时我们成功添加了一位客服账号

3、邀请绑定客服账号

localhost:8080/wx/mp/kefu/inviteBinding

此时,我们填入的客服微信号的微信就会收到微信公众平台发送的绑定邀请:

我们点击模板消息进行绑定:

点击“接受”后,该微信号就与我们公众号的客服账号绑定成功了

4、删除客服账号

localhost:8080/wx/mp/kefu/deleteKf

再次查询客服列表:

发现,我们的客服列表为空了

如您在阅读中发现不足,欢迎留言!!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/777858.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号