WeChat card and coupon interface
1 Notice
To read the card and coupon interface documents, please be sure to read the WeChat public There are two chapters in the general instruction document for platform developers, "WeChat Developer Specifications" and "WeChat Official Account Interface Permission Description", to learn about the WeChat public platform interface Basic calling methods, developer specifications, and handling of exceptions during the calling process.
##2 Apply for a sandbox test account
If you do not have an available card and coupon test account, you can apply for a temporary test number through the WeChat interface test account application tool for card and coupon testing. You can log in to the interface test account to apply Scan through WeChat to get a brand new appid (you already have the permission to create cards and coupons, including friends’ coupons) and appsecret are used for calling the card and coupon interface .
Note: The coupons created by this appid will not be reviewed and approved. They are limited to small-scale testing and cannot be used by developers for other purposes.
##3 Card CouponHelloWorld
Development Readers can use the debug tool to quickly complete the process of creating cards and coupons, placing cards and coupons, and canceling cards and coupons. If you want to understand the card and coupon interface in depth, you need to read the corresponding part of the document in detail.
##Step 1 Obtain access_token
Page address: http://mp.weixin.qq.com/debug/
Interface type: basic support
Interface list: Get access_token interface
Note: Fill in the developer’s appid and secret as parameters
Click Check the problem and return to the access_token. The access_token is valid for two hours. You must obtain it again after two hours.
Step 2 Upload the coupon logo
Page address: http://mp.weixin.qq.com/debug/
Interface type: basic support
Interface list: Upload image material interface
access_token: access_token obtained in the previous step
##buffer: your choice The picture
Click to check the problem and you can get the picture URL. In the next step to create the coupon, you need
##Step 3 Create Card Coupon
Page address: http://mp.weixin.qq.com/debug/
Interface type: Card interface
Interface list: create card coupon interface
access_token: access_token obtained in the first step
JSON example :
{ "card": { "card_type": "GROUPON", "groupon": { "base_info": { "logo_url": "http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmx ibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0", "brand_name":"微信餐厅", "code_type":"CODE_TYPE_TEXT", "title": "132元双人火锅套餐", "sub_title": "周末狂欢必备", "color": "Color010", "notice": "使用时向服务员出示此券", "service_phone": "020-88888888", "description": "不可与其他优惠同享\n如需团购券发票,请在消费时向商户提出\n店内均可使用,仅限堂食", "date_info": { "type": "DATE_TYPE_FIX_TERM", "fixed_term": 15 , "fixed_begin_term": 0 }, "sku": { "quantity": 500000 }, "get_limit": 3, "use_custom_code": false, "bind_openid": false, "can_share": true, "can_give_friend": true, "location_id_list" : [123, 12321, 345345], "custom_url_name": "立即使用", "custom_url": "http://www.qq.com", "custom_url_sub_title": "6个汉字tips", "promotion_url_name": "更多优惠", "promotion_url": "http://www.qq.com" }, "deal_detail": "以下锅底2选1(有菌王锅、麻辣锅、大骨锅、番茄锅、清补凉锅、酸 菜鱼锅可选):\n大锅1份 12元\n小锅2份 16元 "} } }
Note: Unix timestamp is used in date_info. Be sure to change begin_timestamp to be less than the current time and end_timestamp to be after today so that you can test the coupon later. To succeed
Interface address:Create card and coupon interface
Step 4 Create QR code delivery
##Page address: http ://mp.weixin.qq.com/debug/
Interface type: Card interface
Interface list: Create QR code ticket interface
access_token: the access_token obtained in the first step
##JSON example:{
"action_name": "QR_CARD",
"action_info": {
"card": {
"card_id": "po_2DjgJ2zrboM6SzK3qNuje5iWQ",
}
}
}
Create QR code interface
Step 5 Display the QR code
# #Click the link in the show_qrcode_url field when returning from the previous step to display the QR code for card and coupon collection.
Example: https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQEr8ToAAAAAAAAAASxodHRwOi8vd2V********NjRjVuAAIE3kqwVQMEgDPhAQ ==
Open WeChat and scan, and then receive the coupon. If it shows that the coupon has not passed the review, you need to set up a test whitelist in the next step. If you can receive it, ignore step six. .
You can scan the following QR code to experience WeChat coupons:
Step 6 Set up the test whitelist
##Page address: http: //mp.weixin.qq.com/debug/
Interface type: coupon interface
Interface list: Set test whitelist interface
access_token: the access_token obtained in the first step
##JSON example: { "username":["usr1","usr2"] }
Interface address:
Set whitelist interface Step 7 Verify and cancel the card ##Page address: http://mp.weixin.qq.com/debug/ Interface type: Card Interface Interface list: Card cancellation interface access_token: access_token obtained in the first step
JSON example: { "code":"759733467744" }
Note: Only the interface address of the card coupon that has passed the review and is within the validity period is supported: Cancellation interface
4 Overview of card and coupon interface
##The WeChat card and coupon interface mainly sets up a series of interfaces around the creation, collection, placement and verification of cards and coupons. Developers can choose the appropriate interface according to the effect they want to achieve
Carry out development to realize unique card and coupon applications in the industry.
5 Introduction to card terms
The following are the key concepts you need to understand during the card and coupon development process:
parameter name | describe |
card_id | Card ID. A coupon ID corresponds to a type of coupon and contains the code of the corresponding inventory quantity. |
code | Coupon Code. The unique identifier of a card and coupon. This string code is used when canceling the card and coupon. It supports merchant customization. |
##openid | The user’s name under the official account Unique identity. |
##access_token | Credential for calling the interface, validity time It takes 7200s. Each time the request is refreshed, is obtained through the get access_token interface. The developer needs to properly save it and establish a cache mechanism. |
The JS-SDK interface that must be used to call the WeChat web page to call the WeChat native function Signature ticket, for details, see: JS-SDK section | |
api_ticket | The temporary ticket signed when calling the WeChat card and coupon interface is valid for 7200s. Repeated requests within 7200s will remain unchanged. Get api_ticket interfaceGet. |
##card_ext | Additional information for expandable cards , used to place cards and coupons, comes with basic information about the cards and coupons. |
##outer_id | Scenario value of coupon collection channel. Support merchants to fill in the custom scene value into card_ext for issuing cards and coupons. When the user receives the card, the corresponding scene value will be notified to the merchant through an event. |
卡 coupon When the review is passed, the card and coupon are received, the card and coupon are deleted, and the card and coupon are written off , Will push events to notify developers, and the receiving address is the server URL filled in the public platform developer center. | |
Custom entry | Create coupons through API Supports merchants to customize the unit to jump to external links on the card and coupon details page. |
##6 Developer Notes
6.1 WeChat version judgment
The card and coupon function module is only supported after WeChat version 6.0.2 , it is invalid for users of lower version to call JS-SDK. Therefore, the WeChat team recommends that merchants use the user agent to determine the user's current version number before calling the JS-SDK interface added to the card package. Taking the iPhone version as an example, you can obtain the following version sample information through the user agent:
"Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS X) AppleWebKit/534.46(KHTML,like Geocko)Mobile/9B206 MicroMessenger/6.0.2 "
where 6.0.2 is the WeChat version number installed by the user. Merchants can determine whether the version number is higher than or equal to 6.0.2.
6.2 Card and coupon placement restrictions
In the public account session environment, only the call under the domain name of the public account is supported Cards and coupons. Pushing coupons from other merchants within a public account session is not supported without the permission of the platform. Otherwise, users will be prompted when receiving coupons: "Cannot be posted without authorization from the coupon merchant". There is no such restriction outside of public account conversations (such as Moments and conversation environments).
Notes
The behaviors that occur in the public account’s dialog box and the actions that jump from the public account’s dialog box Web links are all within the session environment of the official account.
6.3 Encoding Rules
All API interface POST data only supports UTF-8 encoding, otherwise an error will be returned .
#6.4 Jump External link parameter description
In order to meet the expansion requirements of merchants based on the card and coupon itself, the inner page of the card and coupon is allowed to add a url to jump to the external link.
The external link that the card and coupon jumps out can carry the parameters of the card and coupon information, which is used by developers to confirm the user's identity on the page.
The fields included are encrypt_code, card_id, openid, outer_str (membership card only).
Note: encrypt_code is the encryption code, you need to call Decoding interface to obtain the real Code code . If the specified url is http://www.qq.com, when the user clicks, the redirected url will be: http://www.qq.com?encrypt_code=ENCRYPT_CODE&card_id=CARDID&openid=xxxx&outer_str=xxxxx
##6.5 Contact us
If you encounter problems with card and coupon development, You can contact us via email weixin_card@foxmail.com. You can also join the developer QQ communication group 205482166 512568283. Please be sure to indicate the merchant name and business for verification.
7 Card and coupon data package download
Developers can downloadCard and coupon interface data package:
##-Creation & Signing Tool SDK;
-Card and Voucher Interface Call Flow Chart;
- New interface feature description;
- SDK for Android;
- SDK for iOS;