接口v3/profitsharing/receivers/add
我使用的是平台证书还没有改用微信支付公钥
name参数我使用的平台证书进行了加密,也传递了Wechatpay-Serial平台证书的序列号,但服务端返回 array:2 [ "code" => "PARAM_ERROR" "message" => "平台私钥解密失败" ], 其问下有人知道是怎么回事么?
如果不传name参数是没问题的,但添加商户的时候name是必须的
加密方式用的官方的wechatpay/wechatpay 包,加密代码如下
public static function encrypt(
#[\SensitiveParameter]
string $plaintext,
$publicKey,
int $padding = OPENSSL_PKCS1_OAEP_PADDING
): string
{
self::paddingModeLimitedCheck($padding);
if (!openssl_public_encrypt($plaintext, $encrypted, $publicKey, $padding)) {
throw new UnexpectedValueException('Encrypting the input $plaintext failed, please checking your $publicKey whether or nor correct.');
}
return base64_encode($encrypted);
}
加密要使用微信支付平台公钥或者平台证书,你可以直接这么写:
$instance->v3->profitsharing->receivers->add->postAsync([ 'json' => [ 'sub_mchid' => '1900000109', 'appid' => 'wx8888888888888888', 'sub_appid' => 'wx8888888888888889', 'type' => 'MERCHANT_ID', 'account' => '86693852', 'name' => $encryptor('hu89ohu89ohu89o'), 'relation_type' => 'SERVICE_PROVIDER', 'custom_relation' => '代理商', ], 'headers' => [ 'Wechatpay-Serial' => 'PUB_KEY_ID_0114232134912410000000000000', ], ]) ->then(static function(\Psr\Http\Message\ResponseInterface $response) { print_r(json_decode((string) $response->getBody(), true)); }) ->wait();
需要切换的情况:
如果你是微信支付APIv3的商户,且已经使用了微信支付平台证书,请参考本文指引,将平台证书切换成微信支付公钥模式