zl程序教程

您现在的位置是:首页 >  APP

当前栏目

微信公众号Web开发笔记,持续记录

2023-03-07 09:44:24 时间

官方文档:https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html

微信公众平台开发概述

1.用户识别

为了识别用户,每个用户针对每个公众号会产生一个安全的OpenID,如果需要在多公众号、移动应用之间做用户共通,则需前往微信开放平台,将这些公众号和应用绑定到一个开放平台账号下,绑定后,一个用户虽然对多个公众号和应用有多个不同的OpenID,但他对所有这些同一开放平台账号下的公众号和应用,只有一个UnionID

2.公众号内网页

许多复杂的业务场景,需要通过网页形式来提供服务,这时需要用到:

  1. 网页授权获取用户基本信息:通过该接口,可以获取用户的基本信息(获取用户的 OpenID 是无需用户同意的,获取用户的基本信息则需用户同意)
  2. 微信JS-SDK:是开发者在网页上通过 JavaScript 代码使用微信原生功能的工具包,开发者可以使用它在网页上录制和播放微信语音、监听微信分享、上传手机本地图片、拍照等许多能力。

服务器配置 

开启后,用户发送的消息将自动转发到该配置地址,并且在网站中设置的自动回复和自定义菜单将失效。同时可以通过相关接口进行自定义的消息回复。

相关文档:https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html

消息加解密文档:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Message_encryption_and_decryption.html

消息加解密技术:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Technical_Plan.html

修改配置后,大概在5分钟后才会生效。

安全模式下需要对收到的和即将发送的消息进行加解密。

填写服务器配置时,验证接口和token时,接口若确认此次 GET 请求来自微信服务器,需要原样返回 echostr 参数内容,才可以接入生效,成为开发者,否则接入失败。

基础事件

相关文档:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html

在微信用户和公众号产生交互的过程中,用户的某些操作会使得微信服务器通过事件推送的形式通知到开发者在开发者中心处设置的服务器地址,从而开发者可以获取到该信息。其中,某些事件推送在发生后,是允许开发者回复用户的,某些则不允许

  • 关注/取消关注事件
  • 扫描带参数二维码事件
  • 上报地理位置事件
  • 自定义菜单事件
  • 点击菜单拉取消息时的事件推送
  • 点击菜单跳转链接时的事件推送
  • 模板消息推送是否成功
  • 卡券领取事件

卡券功能

1.基本功能

1.投放卡券:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html

2.客服消息推送卡券:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html#%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%8F%A3-%E5%8F%91%E6%B6%88%E6%81%AF

3.会员卡管理:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Manage_Member_Card.html

4.卡券事件推送:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Coupons_Vouchers_and_Cards_Event_Push_Messages.html

5.删除卡券:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#7

客服消息推送

5.会员卡开卡组件:https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1479824356&version=1&lang=zh_CN&platform=2

addCard接口

2.开卡组件

开卡组件分为跳转型和非跳转型,区别在于跳转型开卡后会跳转自定义的页面。

2.1 跳转型开卡组件

创建跳转型开卡组件需在创建会员卡时,加入如下的字段参数:

"wx_activate" : true,
"wx_activate_after_submit" : true,
"wx_activate_after_submit_url" : "http://mp.weixin.qq.com/wiki"

2.2 非跳转型开卡组件

创建非跳转型开卡组件需在创建会员卡时,加入如下的字段参数:

"wx_activate" : true

3.获取开卡组件链接

开发者可以获取开卡组件的链接,配置于公众号关注回复、自定义菜单等领卡入口内。

# https://api.weixin.qq.com/card/membercard/activate/geturl?access_token= ACCESS_TOKEN

{
   "card_id" : "pbLatji6o5g7hJh8Otuvux4y1ty0",
   "outer_str" : "123"
}

4.获取会员信息

对于跳转型的开卡组件,用户提交信息后,获取的会员卡是未被激活的。商户需要在跳转后的网页使用接口激活会员卡

1.拉取会员信息:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Manage_Member_Card.html#1

2.会员激活:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#_6-1-%E6%8E%A5%E5%8F%A3%E6%BF%80%E6%B4%BB

3.设置一键激活字段:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#_6-2-%E4%B8%80%E9%94%AE%E6%BF%80%E6%B4%BB

5.会员卡信息更新

相关文档:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#_6-3-%E8%87%AA%E5%8A%A8%E6%BF%80%E6%B4%BB

5.创建会员卡

1.自动激活:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#_6-3-%E8%87%AA%E5%8A%A8%E6%BF%80%E6%B4%BB

2.卡券背景颜色:https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Create_a_Coupon_Voucher_or_Card.html#_2-5-%E6%AD%A5%E9%AA%A4%E4%B8%89%EF%BC%9A%E9%80%89%E5%8F%96%E5%8D%A1%E5%88%B8%E8%83%8C%E6%99%AF%E9%A2%9C%E8%89%B2

问题总结

1.回复多条消息

客服消息:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html

被动回复消息:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Passive_user_reply_message.html

单条图文消息

2.带参的二维码

相关文档:https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html

短链转换:https://developers.weixin.qq.com/doc/offiaccount/Account_Management/URL_Shortener.html

用户扫描带场景值二维码时,可能推送以下两种事件:

  • 如果用户还未关注公众号,则用户可以关注公众号,关注后微信会将带场景值关注事件推送给开发者。
  • 如果用户已经关注公众号,在用户扫描后会自动进入会话,微信也会将带场景值扫描事件推送给开发者。

3.上传素材到公众号

相关文档:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html

公众号JSSDK

相关文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html