API Description

In a third-party page, user's operation to draw a red packet is triggered by calling JSAPI. If a user gets a red packet successfully, the native red packet page of Weixin is invoked. A user can only draw red packets via Shake-Nearby feature, and each user can only get one red packet at most under a campaign ID. When creating a red packet campaign, a developer who chooses to use a template page does not need to call this API.

BeaconShakehbJsBridge' is introduced

<scripttype="text/javascript"src="http://zb.weixin.qq.com/app/shakehb/BeaconShakehbJsBridge.js">
</script>

API Description

The JS API for drawing red packets is called in the same format as that for the Weixin JS API, as shown below:

Function: invoke Use: Actively call the specified API General form: BeaconShakehbJsBridge.invoke("API name", {request parameters}); API name: jumpHongbao Parameters: openid, lottery_id, noncestr, sign Callback function: none

Request Parameters

Parameter Description
openid User's openid (required).
lottery_id Red packet campaign ID (required), which comes from lottery_id returned by addlotteryinfo.
noncestr A random string not longer than 32 digits (required).
sign Signature. For more information, see the Signature Generation Rules below.

Signature Generation Rules

  1. Except for the "sign" field, all parameters are sorted in an ascending lexicographical order by the parameter name ASCII code, and joined into the original signature string in a URL key-value format (Param1=value1&Param2=value2...). Any parameter with a null value is excluded from the signature.

  2. In the original signature string, the field names and field values are all original values without being URL-escaped.

  3. Append the key parameter (the key set with the "Create Red Packet Campaign" API) to the original signature string to get the following string: Param1=value1&Param2=value2...&key=keyvalue.

  4. Perform MD5 operation on the resulting string and convert all the characters to uppercase: sign=ToUpperCase(MD5(Param1=value1&Param2=value2…&key=keyvalue))

  5. For the sake of security, developers must implement the signature generation logic on server side.

Request Example

BeaconShakehbJsBridge.ready(function(){
//Redirect to the Draw Red Packet page
    BeaconShakehbJsBridge.invoke('jumpHongbao',{
    lottery\_id:'LOTTERY\_ID ',
    noncestr:'378507853820041854759013507217',
    openid:'OPENID',
    sign:'SIGN'
});
});

Error Codes:

Message for User Error Code Error Message Solution
An error occurred 5 Ticket for Shake-Nearby expired Check whether the user enters the page via the Shake feature.
An error occurred 11002 Ticket for Shake does not exist Check whether the user enters the page via Shake feature.
An error occurred 11003 Ticket for Shake is invalid. Check whether the user enters the page via Shake feature.
An error occurred 11004 Failed to get the merchant appid Check whether the user enters the page via Shake feature.
An error occurred 11005 Failed to check the frequency at which the user draws a red packet using Shake-Nearby feature Check whether the user enters the page via Shake feature.
An error occurred 11009 System error Try again
An error occurred 11010 Random string length exceeded the limit Verification error occurred while calling the JSAPI parameter in custom page. Make a check.
An error occurred 11011 LotteryID parsing failed Verification error occurred while calling the JSAPI parameter in custom page. Make a check.
An error occurred 11012 Signature verification failed Verification error occurred while calling the JSAPI parameter in custom page. Make a check.
An error occurred 11013 Invalid openid Verification error occurred while calling the JSAPI parameter in custom page. Make a check.
An error occurred 11014 Invalid pass_ticket Check whether the user enters the page via Shake feature.
An error occurred 12013 Failed to link the user to the red packet The error returned by WeChat Pay when a user succeeds in drawing a red packet ticket.
An error occurred 12014 Failed to query the red packet ticket by WeChat Pay The error returned by WeChat Pay when a user succeeds in drawing a red packet ticket.
An error occurred 12015 Too many attempts to draw red packets Try again
An error occurred 12019 Invalid page_id Verification error occurred while using the template.