求助课程源码
有源码么?应该会帮助理解!!
有源码么?应该会帮助理解!!
2016-10-15
/**
* curl post/get
* @param $url
* @param string $data
* @return mixed
*/
public static function http_curl($url, $data = '')
{
//2初始化
$ch = curl_init();
//3.设置参数
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //不验证证书
if (!empty($data)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
}
//4.调用接口
$res = curl_exec($ch);
//5.关闭curl
curl_close( $ch );
$arr = json_decode($res, true);
return $arr;
}
/**
* 获取带参数的二维码 临时
*/
public function actionGetTmpQrCode()
{
//获取ticket票据
$access_token = $this->getWxAccessToken();
$url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$access_token;
//{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}
$postArr = [
'expire_seconds' => 604800, //7day
'action_name' => 'QR_SCENE',
'action_info' => [
'scene' => [
'scene_id' => 123
]
]
];
$postJson = json_encode($postArr);
$res = WxHelper::http_curl($url, $postJson);
$ticket = $res['ticket'];
//使用ticket获取二维码图片
$url2 = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . urlencode($ticket);
//$res2 = WxHelper::http_curl($url2);
//展示二维码
echo "<img src='".$url2."'>";
}举报