protected static function getEncrypt($str) { $public_key = config('wx.platformCertificateFilePath');//平台证书,如果是地址,可以使用file_get_content来获取内容 $pu_key = openssl_pkey_get_public($public_key);//这个函数可用来判断公钥是否是可用的 if (empty($pu_key)) throw new Exception('无法获取平台证书'); $encrypted = ''; if (openssl_public_encrypt($str, $encrypted, $pu_key, OPENSSL_PKCS1_OAEP_PADDING)) { //base64编码 $encrypted = base64_encode($encrypted); } else { throw new Exception('加密失败'); } return $encrypted; }
标签:加密,pu,微信,base64,v3,key,encrypted,PHP,public From: https://www.cnblogs.com/bkhdd/p/17756282.html