首页 > 编程知识 正文

建立微信公众号收费吗,微信公众号文章免费模板

时间:2023-05-05 22:51:51 阅读:55390 作者:997

【标题】微信-推送公众号扫码关注信息(带源代码)。

【前言】

我最近在制造需求。 是公众号中常用的功能。 - 《扫码点餐》。

http://www.Sina.com/http://www.Sina.com /

用户关注公众号后,进入关注页面关注后直接进入公众号窗口。

使用openId和模板消息id向用户推送信息。

这样,可以收集用户的openId,将店铺联系起来,后期推送其他模板消息,帮助用户和店铺默默地开通会员卡。

【概要】

另一方面,步骤1实现,生成带有参数的二维码

2、服务器访问指南

3、接受活动推送

和4、3一样

【概要】

http://www.Sina.com/http://www.Sina.com /

noscripth3 class='tips '您的浏览器不支持JavaScript。 请更改浏览器的参数。/H3/noscript % string key=' key _ ' system.current time millis (; string URL=qrauthaction.getqrcodebycache (store name; session.set attribute (XXX _ eq代码_ URL _ ' key,URL ); % divclass=' mydiv ' id=' opacity '/divdivstyle=' margin : auto; width: 100%; padding: 0px; ' id=' ecode _ div ' img alt='二维码' src=' %=serviceurl %/qrauth _ wx _ img.JSP? key=%=key % width=%=width % height=%=height % ' title='扫描码关注' style='max-width: 600px; max-height: 600px; ' id=' QR code '//div http://www.Sina.com /

/** * TODO是token * * @ param appid * @ return */protectedstaticstringgetaccess _ token (string appid,String secret ) ) ) try { stringmainurl=' https://API.weixin.QQ.com/CGI-bin/token? grant _ type=client _ credential appid=' appid ' secret=' secret; RS=net utils.gethtml source (main URL,5000 ); JonobjectJSON=newJSONobject(RS; return JSON.getstring (access _ token ); }catch(exceptione ) logutils.error ) RS,e ); 返回' '; }} 在店铺桌子贴一张固定二维码,用户扫码后进入公众号窗口

/** *编写代码* * @ param access _ token * @ paramqrcodetype * @ return */publicstaticstringcreateqrcode (string acccess _s _ teqreqrcode ) jsonobjectjsonobject1=newjsonobject (; if (string utils.is not blank (QR codetype (1).equals (QR codetype ) )//永久二维码JSONobject1.put(scene_str ),put ) Jon.add(action_name,) QR_LIMIT_STR_SCENE ); JSON.add(action_info )、jsonObject; } else { JSON object1. put (scene _ str ),parames ); JSONobject.put('Scene ',jsonObject1); Jon.add(Expire_s

econds", String.valueOf(1000 * 60 * 60 * 24)); // 有效期:秒json.add("action_name", "QR_STR_SCENE");json.add("action_info", jsonObject);}String createRS = WeiXinNetUtil.postJsonDataToServer(WeiXinUrl.QRCODE_CREATE + "?access_token=" + access_token, json.toString());LogUtils.debug(createRS);JSONObject creJson = new JSONObject(createRS);if (!creJson.has("url")) {return null;}return creJson.getString("url");} catch (Exception e) {e.printStackTrace();return null;}}

4、接收推送消息:

if ("event".equalsIgnoreCase(msgType)) {String event = map.containsKey("Event") ? map.get("Event") : null;if (event != null) {String eventKey = map.containsKey("EventKey") ? map.get("EventKey") : null;// 关注/取消关注事件:if ("subscribe".equalsIgnoreCase(event)) {if (StringUtils.isNotBlank(eventKey)) {eventKey = eventKey.replaceAll("qrscene_", "");Update update = new Update("Account");update.setKey("storeName", eventKey);update.setValue("openid", openId);update.execute(true);}new WeiXinMethod().message_custom_send(openId, "感谢你的关注,我与你同在!!!");SendMessageDing sendMessageDing = new SendMessageDing();sendMessageDing.setTitle("用户关注公众号");sendMessageDing.setLogType("微信");sendMessageDing.setLogInfo("用户{" + openId + "}关注了公众号,绑定了{" + eventKey + "}账号");sendMessageDing.sendAsyn();}if ("unsubscribe".equalsIgnoreCase(event)) {String storeName = DBUtils.getString("select storeName from Account where openId=? limit 1 ", new String[] { openId });SendMessageDing sendMessageDing = new SendMessageDing();sendMessageDing.setTitle("取消关注公众号");sendMessageDing.setLogType("微信");sendMessageDing.setLogInfo("用户{" + openId + "}取消关注公众号,为{" + storeName + "}账号;");sendMessageDing.sendAsyn();DBUtils.execute("update Account set openId=null where openId=? ", new String[] { openId });}if ("scan".equalsIgnoreCase(event)) {if (StringUtils.isNotBlank(eventKey)) {eventKey = eventKey.replaceAll("qrscene_", "");Update update = new Update("SYCM_Account");update.setKey("storeName", eventKey);update.setValue("openid", openId);update.execute(true);}SendMessageDing sendMessageDing = new SendMessageDing();sendMessageDing.setTitle("用户重新扫码进公众号");sendMessageDing.setLogType("微信");sendMessageDing.setLogInfo("用户{" + openId + "}已关注公众号,为{" + eventKey + "}账号!");sendMessageDing.sendAsyn();}if ("click".equalsIgnoreCase(event)) {// @-菜单点击,菜单id匹配:if ("NIUCM_V1001_DOWN".equalsIgnoreCase(eventKey)) {String msg = "地址:https://www.baidu.com/";out.println(WeiXinMethod.getSendPlainMsgXml(openId, toUserId, msg));}}}}

5、推送模板消息给用户:

/** * TODO 模板推送 * * @param map * */public static boolean queueReminderPush(Map<String, Object> map) {String openId = map.get("openId").toString();if (openId == null)return false;String title = map.get("title") == null ? "" : map.get("title").toString();String keyword1 = map.get("keyword1") == null ? "" : map.get("keyword1").toString();String keyword2 = map.get("keyword2") == null ? "" : map.get("keyword2").toString();String detailUrl = map.get("detailUrl") == null ? "" : map.get("detailUrl").toString();String remark = map.get("remark") == null ? "" : map.get("remark").toString();try {String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + AccessTokenUtil.getTokenByDB();Json json = new Json();Json data = new Json();json.add("template_id", WX_APP_TEMPLATE_ID);json.add("url", detailUrl);json.add("topcolor", "#000000");json.add("touser", openId);data.put("first", newWeixinJson(title));data.put("keyword1", newWeixinJson(keyword1));// 商家名称data.put("keyword2", newWeixinJson(keyword2));// 评测结果data.put("remark", newWeixinJson(remark, "#993366"));json.put("data", data);String strRes = NetUtils.getHtmlSourcePost(url, json.toString());LogUtils.debug(strRes);JSONObject obj = new JSONObject(strRes);if (obj.has("errcode") && !"0".equalsIgnoreCase(obj.getString("errcode"))) {return false;}return true;} catch (Exception e) {return false;}}

 

三、附件-代码:

代码地址:https://download.csdn.net/download/qq_26599807/12107121 密码:lcl20200116

如遇代码不能用,麻烦给作者留言,百忙之中尽量给以回复。

Ⅰ、可能原因:

1、尚未更新地址(最后编辑:2020-01-19 14:13:11)

2、资源未审核通过,一个小时后重试

3、资源被和谐了

4、not other...

Ⅱ、代码说明:

1、SendMessageDing类为推送服务消息日志类,可忽略。

2、QRImageUtils和qrauth_wx_img.jsp是二维码java生成方式,可自行度娘。

3、类似DBUtils和Update的是数据库操作封装类,可使用自己项目传统方式。

4、CacheUtils缓存、StringUtils字符串判断及转型。

 

 

作者附言:如果本文章帮到了您,劳烦动动贵手点个赞,关注一下,谢谢^_^

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。