No matter e-commerce CPS or takeout CPS, there are so many third-party CPS interfaces, only Meituan Alliance provides the order data push back interface, and as long as the order status changes, the data will be pushed back, which provides a great friendly help for our own system to realize the function of user tracking and then distribution fission.

Log in the background of Meituan Alliance, and find a column named “Order Push-back Interface” in the API list of alliance.

Yes, this is the interface we need. Click on it to see the details.

As with most callback interface, this interface does not need access to take the initiative to call, but access to the party to provide an interface to platform invoke Meituan alliance, platform will order data on post to this interface, thus we can obtain from the data to the order in advance of the incoming sid, the sid is can only identify the user of our system. This can achieve the effect of order tracking, and then do some business logic processing.

For security, it is also necessary to check the data posted by the alliance platform to ensure that it is the data sent by the platform. Note that the key used for verification is not the same as the key used to call other interfaces of the alliance platform. This key is in the following position and the signature mode is the same as that of other interfaces.

Take a look at the service layer code

{"errcode":"0","errmsg":" OK "}, {"errcode":"1","errmsg":"err"}

@Override public Map<String, String> mtOrderCallback(TreeMap<String, String> params) { String data = JSON.toJSONString(params); Logger. info(" Meituancallback: {}", data); MtOrderModel mtOrder = JSONObject.parseObject(data, MtOrderModel.class); String getSign = mtOrder.getSign(); String sign = MtSignUtils.genSign(params, model.getMtCallbackSecret()); Map<String, String> result = new HashMap<>(3); if (sign.equals(getSign)) { String userUuid = mtOrder.getSid(); UserMember member = userMemberService.getOne(Wrappers.<UserMember>lambdaQuery().eq(UserMember::getUuid, userUuid)); if (member ! = null) { String orderId = mtOrder.getOrderid(); String status = mtOrder.getStatus(); String type = mtOrder.getType(); CpsOrder order = cpsOrderService.getOne(Wrappers.<CpsOrder>lambdaQuery() .eq(CpsOrder::getOrderSn, orderId)); if (order == null) { order = new CpsOrder(); // TODO // save the order //...... cpsOrderService.save(order); } else {the if (StringUtils. Equals (" 8 ", status)) {/ / Meituan order has been completed / /... } else if (stringutils.equals ("9", status)) {// Meituanorder refunded or risk control //...... } cpsOrderService.updateById(order); } } result.put("errcode", "0"); result.put("errmsg", "ok"); } else { result.put("errcode", "1"); result.put("errmsg", "err"); } logger.info(" {}", json.tojsonString (result)); return result; }Copy the code

Look at the code for the Controller layer

@PostMapping("mtOrderCallback")
public Map<String, String> mtOrderCallback(@RequestBody TreeMap<String, String> params){
    return mtApiService.mtOrderCallback(params);
}
Copy the code

Finally, you must remember to configure the interface address on the alliance platform, so you are done.

How does Meituan alliance realize the function of user order tracking

The mountains and rivers have met, the future can be, thank you for reading, goodbye

The golden staff in my hands can reach the sky up and explore the sea down

Select your targeted customers from short videos – Douyin Edition