参考文档为微信平台小微入驻文档
/**
* publicKeyEncrypt 对身份证等敏感信息加密
* @param string $string
* @return string
* @throws WxException
*/
protected function publicKeyEncrypt(string $string)
{
$crypted = '';
$publicKey = $this->getPublicKey();
if ($publicKey) {
$publicKeyResource = openssl_get_publickey($publicKey);
$f = openssl_public_encrypt($string, $crypted, $publicKeyResource, OPENSSL_PKCS1_PADDING);
openssl_free_key($publicKeyResource);
if ($f) {
return base64_encode($crypted);
}
}
throw new WxException(20002);
}
/**
* MakeSign 生成签名
* @param $data
* @param string $signType
* @return string
*/
protected function makeSign(array $data, $signType = 'HMAC-SHA256')
{
//签名步骤一:按字典序排序参数
ksort($data);
$string = $this->toUrlParams($data);
//签名步骤二:在string后加入KEY
$string = $string . "&key=" . $this->diy_key;//. $this->aes_key;
//签名步骤三:MD5加密或者HMAC-SHA256
if ($signType == 'md5') {
//如