作者 王智

baoxiu22

... ... @@ -207,30 +207,37 @@ class Common extends Api
{
//公众号所有粉丝openid
$LikeOpenid = $this->ListOpenid();
$options = [
'app_id' => 'wx3b0bb7a5d1e0722d', // AppID
'secret' => '104ac7dbcc57b778a7319d35d38ed9cd',
];
$app = new Application($options);
$userService = $app->user;
$users = $userService->batchGet($LikeOpenid);
dump($users);
die;
$notice = $app->notice;
$messageId = $notice->send([
'touser' => 'obtaR4jKqAts5e4Rp6ofEw7ftaes',
'template_id' => '3KUsUjjFnf3sf3meWIkAiVFhMM5U7Jgn3kyJFMFNPVc',
// 'url' => 'xxxxx',
'data' => [
'first' => 1,
'keyword1' => 2,
'keyword2' => 2,
'keyword3' => 2,
'keyword4' => 2,
'keyword5' => 2,
'remark' => 1
],
]);
return $messageId;
foreach ($LikeOpenid as $k => $v) {
$LikeOpenid[$k]['lang'] = 'zh_CN';
}
$token = $this->AccessToken();
$data['user_list'] = $LikeOpenid;
$res = $this->curlPost1('https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=' . $token, $data);
dump($res);
// $options = [
// 'app_id' => 'wx3b0bb7a5d1e0722d', // AppID
// 'secret' => '104ac7dbcc57b778a7319d35d38ed9cd',
// ];
// $app = new Application($options);
// $userService = $app->user;
// $users = $userService->batchGet($LikeOpenid);
// dump($users);
// die;
// $notice = $app->notice;
// $messageId = $notice->send([
// 'touser' => 'obtaR4jKqAts5e4Rp6ofEw7ftaes',
// 'template_id' => '3KUsUjjFnf3sf3meWIkAiVFhMM5U7Jgn3kyJFMFNPVc',
//// 'url' => 'xxxxx',
// 'data' => [
// 'first' => 1,
// 'keyword1' => 2,
// 'keyword2' => 2,
// 'keyword3' => 2,
// 'keyword4' => 2,
// 'keyword5' => 2,
// 'remark' => 1
// ],
// ]);
// return $messageId;
}
}
... ...
... ... @@ -406,4 +406,37 @@ class Api
$dist = $userService->lists($nextOpenId = null); // $nextOpenId 可选
return $dist['data']['openid'];
}
// 通过CURL发送HTTP请求
public function curlPost1($url, $postFields)
{
$postFields = json_encode($postFields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8' //json版本需要填写 Content-Type: application/json;
)
);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$ret = curl_exec($ch);
if (false == $ret) {
$result = curl_error($ch);
} else {
$rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 != $rsp) {
$result = "请求状态 " . $rsp . " " . curl_error($ch);
} else {
$result = $ret;
}
}
curl_close($ch);
return $result;
}
}
... ...