First, error prompt

'{"errcode":40169,"errmsg":"invalid length for scene, or the data is not json string hint: [MHecNHnre-dcD9Wa]"}'
Copy the code
  • Cause: The scene parameter exceeds 32 bits

Ii. Official documents, as shown in the figure

Three, the solution (some methods do not cure the root cause)

(1) Request interface mode

  • Encrypt scene data with MD5;
  • Backend redis:key-value (scene:scene text after MD5 encryption) or data table store scene data;
  • After the small program obtains the scene, it requests the back-end interface to obtain the pre-encryption data according to the value after MD5.

(2) Shorten the parameter name

  • Such as:
$param['user_id'] = 999;
$param['shopper'] = 3;
$data['scene'] = http_build_query($param);
Copy the code
  • Shortened to:
$param['u'] = 999;
$param['s'] = 3;
$data['scene'] = http_build_query($param);
Copy the code

(3) English characters separate parameters, and the front-end convention of each position of the value represents the meaning (recommended)

  • Such as:
$param['user_id'] = 999;
$param['shopper'] = 3;
$data['scene'] = http_build_query($param);
Copy the code
  • Can use English characters,; _, as follows
$userId = 999;
$shopper = 3;
$data['scene'] =  $userId . '; ' . $shopper;
Copy the code