/**
* InfoStr APP登录需要的的infostr
*
* @return String
*/
public function infoStr()
{
$infoStr = http_build_query([
'apiname' => 'com.alipay.account.auth',
'method' => 'alipay.open.auth.sdk.code.get',
'app_id' => $this->app_id,
'app_name' => 'mc',
'biz_type' => 'openservice',
'pid' => $this->pid,
'product_id' => 'APP_FAST_LOGIN',
'scope' => 'kuaijie',
'target_id' => mt_rand(999, 99999), //商户标识该次用户授权请求的ID,该值在商户端应保持唯一
'auth_type' => 'AUTHACCOUNT', // AUTHACCOUNT代表授权;LOGIN代表登录
'sign_type' => 'RSA2',
]);
$infoStr .= '&sign='.$this->enRSA2($infoStr);
return $infoStr;
}
/**
* enRSA2 RSA加密
*
* @param String $data
* @return String
*/
private function enRSA2($data)
{
//$this->private_key//应用私钥
$str = chunk_split(trim($this->private_key), 64, "\n");
$key = "-----BEGIN RSA PRIVATE KEY-----\n$str-----END RSA PRIVATE KEY-----\n";
// $key = file_get_contents(storage_path('rsa_private_key.pem')); 为文件时这样引入
$signature = '';
$signature = openssl_sign($data, $signature, $key, OPENSSL_ALGO_SHA256)?base64_encode($signature):NULL;
return $signature;
}
PHP服务端生成支付宝infostr
最新推荐文章于 2024-06-21 16:58:09 发布