国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

網(wǎng)站開發(fā)頂崗實(shí)踐總結(jié)醫(yī)院營銷策略的具體方法

網(wǎng)站開發(fā)頂崗實(shí)踐總結(jié),醫(yī)院營銷策略的具體方法,微信管理系統(tǒng)免費(fèi)版,做房地產(chǎn)公司網(wǎng)站的費(fèi)用當(dāng)你關(guān)注公眾號(hào),然后在公眾號(hào)里面發(fā)送消息,會(huì)收到回復(fù),這個(gè)就是客服消息 參考文檔:接收普通消息 接收事件推送 客服接口-發(fā)消息 想要對(duì)接客服消息,首先要獲取access_token,這個(gè)可以參考我之前的文章:對(duì)接微信公眾號(hào)-CSDN博客 回…

當(dāng)你關(guān)注公眾號(hào),然后在公眾號(hào)里面發(fā)送消息,會(huì)收到回復(fù),這個(gè)就是客服消息

參考文檔:接收普通消息?接收事件推送? 客服接口-發(fā)消息

想要對(duì)接客服消息,首先要獲取access_token,這個(gè)可以參考我之前的文章:對(duì)接微信公眾號(hào)-CSDN博客

?回復(fù)消息的方式

回復(fù)消息的方式有兩種,一種是接收到用戶消息后直接在response里面回復(fù),文檔:回復(fù)文本消息 | 微信開放文檔

這種方式比較簡單,缺點(diǎn)是必須保證在5s內(nèi)回復(fù),否則會(huì)重試,不知道你有沒有遇到過以下場景,當(dāng)你發(fā)送一條消息,過了一會(huì)突然收到好幾條相同的信息,就是卡頓重試造成的。

還有一種方式是客服消息,這種是后臺(tái)主動(dòng)給用戶發(fā)消息, 功能更加強(qiáng)大,不僅僅可以回復(fù)用戶消息,還可以在用戶關(guān)注公眾號(hào),掃描二維碼,點(diǎn)擊菜單時(shí)回復(fù)用戶消息,參考文檔:客服接口-發(fā)送消息

?由于客服消息是異步發(fā)送,在發(fā)送的過程中我們可以調(diào)用客服輸入狀態(tài)接口,實(shí)現(xiàn)以下效果

用戶體驗(yàn)更好,參考文檔: 客服輸入狀態(tài)

客服消息規(guī)則如下,就是說如果用戶發(fā)送了消息,你可以在48小時(shí)內(nèi)下發(fā)最多5條消息

場景下發(fā)額度額度有效期
用戶發(fā)送消息5條48小時(shí)
點(diǎn)擊自定義菜單3條1分鐘
關(guān)注公眾號(hào)3條1分鐘
掃描二維碼3條1分鐘

如何對(duì)接服務(wù)器,如何接收消息可以看我之前寫的博客:?對(duì)接微信公眾號(hào)-CSDN博客

?Java代碼實(shí)現(xiàn)

以下代碼實(shí)現(xiàn)了客服回復(fù)文本消息,圖文消息和圖片消息

當(dāng)用戶輸入文本則回復(fù)你好,輸入圖文則返回一篇新聞,輸入圖片則返回一張圖片

@RestController
@RequestMapping("/wx")
@Api(tags = "微信管理")
public class WxController {@Autowiredprivate WeixinService weixinService;@RequestMapping("receiveWeixin")@ApiOperation(value = "接收微信消息")public void receiveWeixin(String signature, String timestamp, String nonce, String echostr,HttpServletRequest request, HttpServletResponse response) {try {//服務(wù)器校驗(yàn)String token = "123456";List<String> list = new ArrayList<>();list.add(token);list.add(timestamp);list.add(nonce);list = CollectionUtil.sort(list, (o1, o2) -> o1.compareTo(o2));String str = CollectionUtil.join(list, "");if (!signature.equals(SecureUtil.sha1(str))) {return;}if (StringUtils.isNotEmpty(echostr)) {//校驗(yàn)服務(wù)器response.getOutputStream().write(echostr.getBytes());response.getOutputStream().flush();return;}//接收消息Document document = XmlUtil.readXML(request.getInputStream());Map map = XmlUtil.xmlToMap(document);JSONObject json = JSONObject.parseObject(JSONObject.toJSON(map).toString()).getJSONObject("xml");System.out.println(json);//消息類型String msgType = json.getString("MsgType");//公眾號(hào)微信賬號(hào)String account = json.getString("ToUserName");if (msgType.equals("event")) {// 處理事件消息,比如當(dāng)用戶關(guān)注公眾號(hào)可以下發(fā)個(gè)歡迎消息} else if (msgType.equals("text")) {// 處理用戶消息WeixinReceiveText weixinReceiveText = JSONObject.parseObject(json.toJSONString(), WeixinReceiveText.class);ThreadUtil.execAsync(() -> weixinService.replyMessage(weixinReceiveText.getFromUserName(), weixinReceiveText.getContent()));}} catch (Exception e) {e.printStackTrace();}}@PostMapping(value = "/uploadMaterial")@ApiOperation(value = "上傳資源")public JSONObject uploadMaterial(MultipartFile file) {return weixinService.addMaterial(file, "image");}
}
@Service
public class WeixinService {protected static Logger logger = LoggerFactory.getLogger(WeixinService.class);private final String TOKEN_KEY = "WEIXIN_TOKEN:";@Autowiredprivate RedisTemplate redisTemplate;private final static String appId = "你的appid";private final static String appsecret = "你的appsecret";public WxUser getUserInfoByCode(String code) {String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={}&secret={}&code={}&grant_type=authorization_code";url = StrUtil.format(url, appId, appsecret, code);String res = HttpUtil.get(url);JSONObject tokenInfo = handleResult(res);String token = tokenInfo.getString("access_token");String openid = tokenInfo.getString("openid");String userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token={}&openid={}&lang=zh_CN";userInfoUrl = StrUtil.format(userInfoUrl, token, openid);res = HttpUtil.get(userInfoUrl);JSONObject userInfoJson = handleResult(res);return JSONObject.parseObject(userInfoJson.toJSONString(), WxUser.class);}public synchronized String getToken() {String redisKey = TOKEN_KEY + appId;String token = (String) redisTemplate.opsForValue().get(redisKey);if (StrUtil.isNotEmpty(token)) return token;JSONObject params = new JSONObject();params.put("grant_type", "client_credential");params.put("appid", appId);params.put("secret", appsecret);String str = HttpUtil.post(WeixinConstants.ACCESS_TOKEN_URL, params.toJSONString());JSONObject result = handleResult(str);token = result.getString("access_token");redisTemplate.opsForValue().set(redisKey, token, result.getIntValue("expires_in"), TimeUnit.SECONDS);return token;}private JSONObject handleResult(String str) {JSONObject result = JSONObject.parseObject(str);if (StrUtil.isNotBlank(result.getString("errcode"))) {if (result.getString("errcode").equals("0")) {return result;}if (result.getString("errcode").equals("40014")) {clearToken(appId);}throw new RuntimeException(StrUtil.format("微信接口出錯(cuò), errcode: {}, msg: {}", result.getString("errcode"), result.getString("errmsg")));}return result;}public void clearToken(String appId) {String redisKey = TOKEN_KEY + appId;redisTemplate.delete(redisKey);}public JSONObject getMenuInfo() {String token = getToken();String str = HttpUtil.get(StrUtil.format(WeixinConstants.GET_MENU_INFO_URL, token));JSONObject result = handleResult(str);JSONObject menuInfo = result.getJSONObject("selfmenu_info");if (menuInfo == null) {menuInfo = new JSONObject();}return menuInfo;}public void createMenu(String menu) {String token = getToken();String str = HttpUtil.post(StrUtil.format(WeixinConstants.CREATE_MENU_URL, token), menu);handleResult(str);}public void customSend(String openId, String message) {String token = getToken();JSONObject body = new JSONObject();body.put("touser", openId);body.put("msgtype", "text");JSONObject content = new JSONObject();body.put("text", content);content.put("content", message);String str = HttpUtil.post(StrUtil.format(WeixinConstants.CUSTOM_SEND_URL, token), body.toJSONString());handleResult(str);}/*** 發(fā)送圖片消息*/public void customSendPic(String openId, String mediaId) {String token = getToken();JSONObject body = new JSONObject();body.put("touser", openId);body.put("msgtype", "image");JSONObject image = new JSONObject();body.put("image", image);image.put("media_id", mediaId);String str = HttpUtil.post(StrUtil.format(WeixinConstants.CUSTOM_SEND_URL, token), body.toJSONString());handleResult(str);}public void customSendPicText(String openId, WeixinPicTextVO weixinPicTextVO) {String token = getToken();JSONObject body = new JSONObject();body.put("touser", openId);body.put("msgtype", "news");JSONObject news = new JSONObject();body.put("news", news);JSONArray articles = new JSONArray();news.put("articles", articles);articles.add(weixinPicTextVO);String str = HttpUtil.post(StrUtil.format(WeixinConstants.CUSTOM_SEND_URL, token), body.toJSONString());handleResult(str);}// type: image, voice, video, thumbpublic JSONObject addMaterial(MultipartFile file, String type) {File dir = null;try {String token = getToken();String url = StrUtil.format(WeixinConstants.ADD_METERIAL_URL, token, type);//獲取臨時(shí)文件夾目錄String tempPath = System.getProperty("java.io.tmpdir");String dirName = UUID.randomUUID().toString();dir = new File(tempPath + dirName);dir.mkdirs();File tempFile = new File(dir.getAbsolutePath() + File.separator + file.getOriginalFilename());tempFile.deleteOnExit();file.transferTo(tempFile);HashMap<String, Object> paramMap = new HashMap<>();paramMap.put("media", tempFile);String str = HttpUtil.post(url, paramMap);return handleResult(str);} catch (Exception e) {throw new RuntimeException("上傳文件出錯(cuò)", e);} finally {FileUtil.del(dir);}}// command: Typing,CancelTypingpublic void customTyping(String openId, String command) {String token = getToken();JSONObject body = new JSONObject();body.put("touser", openId);body.put("command", command);String str = HttpUtil.post(StrUtil.format(WeixinConstants.CUSTOM_TYPING_URL, token), body.toJSONString());handleResult(str);}public void replyMessage(String openId, String content) {try {customTyping(openId, "Typing");if ("文本".equals(content)) {customSend(openId, "你好");} else if ("圖文".equals(content)) {WeixinPicTextVO weixinPicTextVO = new WeixinPicTextVO();weixinPicTextVO.setTitle("年輕人開始流行三無婚禮");weixinPicTextVO.setDescription("近年來,越來越多的年輕人告別繁雜冗余的俗套,簡化儀式和環(huán)節(jié),選擇流程簡單、時(shí)間充裕的極簡婚禮");weixinPicTextVO.setUrl("https://www.jnnews.tv/guanzhu/p/2024-01/15/1027166.html");weixinPicTextVO.setPicurl("https://www.jnnews.tv/a/10001/202401/bdabe3e9925a31e867137ed95f722edc.jpeg");customSendPicText(openId, weixinPicTextVO);} else if ("圖片".equals(content)) {// mediaId通過addMaterial獲得customSendPic(openId, "im8rzmF--MD8vDCSnju1oif7lPzvgBMUepg0X1gh8CR6iD2L27CcxLhouIMigR2F");}} catch (Exception e) {logger.error("微信客服消息出錯(cuò): {}", e);} finally {customTyping(openId, "CancelTyping");}}
}
public class WeixinConstants {/*** 獲取token*/public static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/stable_token";/*** 獲取菜單*/public static final String GET_MENU_INFO_URL = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token={}";/*** 創(chuàng)建菜單*/public static final String CREATE_MENU_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={}";/*** 客服接口-發(fā)消息*/public static final String CUSTOM_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={}";/*** 客服接口-輸入狀態(tài)*/public static final String CUSTOM_TYPING_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token={}";/*** 添加素材*/public static final String ADD_METERIAL_URL = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={}&type={}";
}
@Data
@ApiModel(value = "WeixinReceiveText", description = "WeixinReceiveText")
public class WeixinReceiveText extends WeixinBaseVO {private String Content;private String MsgId;private String MsgDataId;private String Idx;
}
@Data
public class WeixinPicTextVO {private String title;private String description;private String url;private String picurl;
}

http://aloenet.com.cn/news/44029.html

相關(guān)文章:

  • web網(wǎng)站開發(fā)試題成都seo培
  • 怎么成立網(wǎng)站企業(yè)網(wǎng)站推廣的形式有
  • 德陽網(wǎng)站建設(shè)平臺(tái)永久免費(fèi)不收費(fèi)的污染app
  • 網(wǎng)站開發(fā)個(gè)人簡歷網(wǎng)絡(luò)營銷服務(wù)平臺(tái)
  • 網(wǎng)站丟失了怎么辦啊西安seo培訓(xùn)機(jī)構(gòu)
  • 阿壩州城鄉(xiāng)建設(shè)網(wǎng)站百度競價(jià)廣告
  • 寧波網(wǎng)站推廣平臺(tái)推薦深圳排名seo公司
  • 免費(fèi)一級(jí)域名網(wǎng)站網(wǎng)站一般需要怎么推廣
  • 360的網(wǎng)站排名怎么做seo排名優(yōu)化app
  • 企業(yè)網(wǎng)站的主要功能愛站網(wǎng)ip反查域名
  • 做國外網(wǎng)站獨(dú)特密碼有什么平臺(tái)可以推廣信息
  • 徐州網(wǎng)站建設(shè)公司百度推廣開戶費(fèi)用標(biāo)準(zhǔn)
  • 大旺建設(shè)局網(wǎng)站自己做網(wǎng)站的流程
  • 滕州網(wǎng)站建設(shè)制作b2b商務(wù)平臺(tái)
  • 政府類門戶網(wǎng)站cms抖音推廣引流
  • 青島網(wǎng)站建設(shè)全包谷歌seo是做什么的
  • 網(wǎng)站怎么推廣網(wǎng)絡(luò)營銷是以什么為基礎(chǔ)
  • 高創(chuàng)園網(wǎng)站建設(shè)方案怎樣制作網(wǎng)站
  • 宿遷裝飾網(wǎng)站建設(shè)公司排名seo是什么工作內(nèi)容
  • 網(wǎng)站建設(shè)服務(wù)費(fèi)屬于站長工具是什么
  • 成都 企業(yè)網(wǎng)站建設(shè)公司價(jià)格百度站長管理平臺(tái)
  • 臺(tái)州做網(wǎng)站的公司seo優(yōu)化實(shí)訓(xùn)總結(jié)
  • github做網(wǎng)站空間地推掃碼平臺(tái)
  • wordpress 焦點(diǎn)圖seo搜索引擎優(yōu)化課程
  • 優(yōu)秀網(wǎng)站設(shè)計(jì)書籍微信公眾號(hào)平臺(tái)官網(wǎng)
  • 返利網(wǎng)網(wǎng)站怎么做北京seo推廣服務(wù)
  • 深圳龍華大浪做網(wǎng)站公司知乎營銷平臺(tái)
  • 做搜狗手機(jī)網(wǎng)站快速排十大中文網(wǎng)站排名
  • 做網(wǎng)站首頁需要什么資料推廣app用什么平臺(tái)比較好
  • 太原自助建站軟件快速排名教程