Skip to content

Instantly share code, notes, and snippets.

@JellyBool
Last active August 1, 2019 07:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save JellyBool/406adefb2707a0e0780b to your computer and use it in GitHub Desktop.
Save JellyBool/406adefb2707a0e0780b to your computer and use it in GitHub Desktop.
alipay payment gateway verify
<?php
protected function isFromAlipay($notifyId)
{
$url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&partner=' . trim(env('ALIPAY_PID')) . '&notify_id=' . $notifyId;
$response = $this->httpGet($url);
return (bool) preg_match("/true$/i",$response);
}
protected function httpGet($url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
curl_setopt($curl, CURLOPT_CAINFO, public_path() . '/cacert.pem');//证书地址
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment