服务器返回类似这样的消息:
{"code":"SIGN_ERROR","detail":{"detail":{"issue":"sign not match"},"field":"signature","location":"authorization","sign_information":{"method":"POST","sign_message_length":120,"truncated_sign_message":"POST\n/v3/marketing/favor/users/ozZALxGLyrqX8B6tRZ3YD223SeV8/coupons\n1573718916\ncPZIprqvk32O6nMNHjBKxsiRDCU1TQel\n{\"s\":1}\n","url":"/v3/marketing/favor/users/ozZALxGLyrqX8B6tRZ3YD223SeV8/coupons"}},"message":"错误的签名,验签失败"}
可以确认sign_message_length和sign_message和本地用于计算签名的数据是完全一致的。
另外测试发现如果把POST消息的body填"{}",就不会返回签名报错,而是返回接口参数缺失:
{"code":"PARAM_ERROR","detail":{"field":"/SendCouponRequest/stock_id","location":"body"},"message":"参数“批次id”是必填项"}
麻烦官方大大不要再回复 https://wechatpay-api.gitbook.io/wechatpay-api-v3/chang-jian-wen-ti/qian-ming-xiang-guan 。给点实际性的提示,谢谢!
问题已解决,是签名的时候,body里面的json字符串,双引号被加上了转义符。希望对后来者有帮助!