This method is suitable for high-concurrency flash sales and rush-buying scenarios, such as a few, dozens, or hundreds of goods in stock, but hundreds of thousands of users may participate in rush-buying at the same time.
Login
In this scenario, it is not suitable to directly follow the normal purchase process. High concurrency and instantaneous peaks may cause your application to be very stuck or even inaccessible. The correct approach should be as follows:
# Set up the flash sale entrance page separately
For such activities, a separate event entry page should be set up, and hundreds of thousands of users should not be directed directly to the application homepage or other unrelated applications. It would be a very good choice to create a static landing advertising page (because this page will be visited by hundreds of thousands of users at the same time);
This page introduces event information and product information, and then places a "Buy Now" button. After clicking the button, this interface is called:
# Interface description
```javascript
WXAPI.goodsSeckillGrab(token, goodsId, seconds)
```
+ token user login credentials
+ goodsId is the product id
+ seconds is the reservation time of the quota. After this time, the system will recalculate the available quota according to the actual remaining inventory of the product; generally setting it to 60 seconds is more suitable;
Return example:
```json
{
"code": 0,
"data": {
"stores": 9986,
"grabkey": "45e80054-d293-4c8d-9467-33f7b9cedeb0"
},
"msg": "success"
}
```
```json
{
"code": 10000,
"data": 0,
"msg": "Sold out"
}
```
```json
{
"code": 20000,
"msg": "goodsId is incorrect"
}
```
## Return value description
If the code returns 0, it means that the user has grabbed the flash sale quota. At this time, the user is guided to the real order purchase page to place an order. When placing an order, the grabkey parameter needs to be passed;
If the code returns 10000, it means that the quota of users who are placing orders at this time is full. At this time, the user can be prompted to try again later; if some users give up the order midway, or cancel the order after placing the order, or have not paid for a long time, the inventory will be released, and the user will still have the opportunity to get the flash sale quota and enter the ordering interface to place the order.