<?php
//get接口
function request_get($url)
{
$ch = curl_init();
$opts = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
);
curl_setopt_array($ch, $opts);
//执行cURL操作
$output = curl_exec($ch);
if (curl_errno($ch)) {
//cURL发生错误处理操作
var_dump(curl_error($ch));
die;
}
curl_close($ch);
return $output;
}
//POST访问
function post( $url, $data ) {
$data = json_encode($data);
//初使化init方法
$ch = curl_init();
//指定URL
curl_setopt( $ch, CURLOPT_URL, $url );
//设定请求后返回结果
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
//声明使用POST方式来进行发送
curl_setopt( $ch, CURLOPT_POST, 1 );
//发送什么数据呢
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
//忽略证书
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
//忽略header头信息
curl_setopt( $ch, CURLOPT_HEADER, 0 );
//设置超时时间
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
//发送请求
$output = curl_exec( $ch );
//关闭curl
curl_close( $ch );
//返回数据
return $output;
}
//调用接口:
$post = array(
'type' => 'itemDel',
'data'=>array('_id'=>$_POST['id'])
);
$posturl = "https://api.weixin.qq.com/XXX";
$a = post($posturl, $post); //请求数据
$rs = json_decode(json_decode($a)->resp_data)->success; //解码第一层JSON
php访问接WEBAPI接口
最新推荐文章于 2023-06-19 16:19:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)