作者 王智

baoxiu22

@@ -207,30 +207,37 @@ class Common extends Api @@ -207,30 +207,37 @@ class Common extends Api
207 { 207 {
208 //公众号所有粉丝openid 208 //公众号所有粉丝openid
209 $LikeOpenid = $this->ListOpenid(); 209 $LikeOpenid = $this->ListOpenid();
210 - $options = [  
211 - 'app_id' => 'wx3b0bb7a5d1e0722d', // AppID  
212 - 'secret' => '104ac7dbcc57b778a7319d35d38ed9cd',  
213 - ];  
214 - $app = new Application($options);  
215 - $userService = $app->user;  
216 - $users = $userService->batchGet($LikeOpenid);  
217 - dump($users);  
218 - die;  
219 - $notice = $app->notice;  
220 - $messageId = $notice->send([  
221 - 'touser' => 'obtaR4jKqAts5e4Rp6ofEw7ftaes',  
222 - 'template_id' => '3KUsUjjFnf3sf3meWIkAiVFhMM5U7Jgn3kyJFMFNPVc',  
223 -// 'url' => 'xxxxx',  
224 - 'data' => [  
225 - 'first' => 1,  
226 - 'keyword1' => 2,  
227 - 'keyword2' => 2,  
228 - 'keyword3' => 2,  
229 - 'keyword4' => 2,  
230 - 'keyword5' => 2,  
231 - 'remark' => 1  
232 - ],  
233 - ]);  
234 - return $messageId; 210 + foreach ($LikeOpenid as $k => $v) {
  211 + $LikeOpenid[$k]['lang'] = 'zh_CN';
  212 + }
  213 + $token = $this->AccessToken();
  214 + $data['user_list'] = $LikeOpenid;
  215 + $res = $this->curlPost1('https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=' . $token, $data);
  216 + dump($res);
  217 +// $options = [
  218 +// 'app_id' => 'wx3b0bb7a5d1e0722d', // AppID
  219 +// 'secret' => '104ac7dbcc57b778a7319d35d38ed9cd',
  220 +// ];
  221 +// $app = new Application($options);
  222 +// $userService = $app->user;
  223 +// $users = $userService->batchGet($LikeOpenid);
  224 +// dump($users);
  225 +// die;
  226 +// $notice = $app->notice;
  227 +// $messageId = $notice->send([
  228 +// 'touser' => 'obtaR4jKqAts5e4Rp6ofEw7ftaes',
  229 +// 'template_id' => '3KUsUjjFnf3sf3meWIkAiVFhMM5U7Jgn3kyJFMFNPVc',
  230 +//// 'url' => 'xxxxx',
  231 +// 'data' => [
  232 +// 'first' => 1,
  233 +// 'keyword1' => 2,
  234 +// 'keyword2' => 2,
  235 +// 'keyword3' => 2,
  236 +// 'keyword4' => 2,
  237 +// 'keyword5' => 2,
  238 +// 'remark' => 1
  239 +// ],
  240 +// ]);
  241 +// return $messageId;
235 } 242 }
236 } 243 }
@@ -406,4 +406,37 @@ class Api @@ -406,4 +406,37 @@ class Api
406 $dist = $userService->lists($nextOpenId = null); // $nextOpenId 可选 406 $dist = $userService->lists($nextOpenId = null); // $nextOpenId 可选
407 return $dist['data']['openid']; 407 return $dist['data']['openid'];
408 } 408 }
  409 +
  410 +
  411 + // 通过CURL发送HTTP请求
  412 + public function curlPost1($url, $postFields)
  413 + {
  414 + $postFields = json_encode($postFields);
  415 + $ch = curl_init();
  416 + curl_setopt($ch, CURLOPT_URL, $url);
  417 + curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  418 + 'Content-Type: application/json; charset=utf-8' //json版本需要填写 Content-Type: application/json;
  419 + )
  420 + );
  421 + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  422 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  423 + curl_setopt($ch, CURLOPT_POST, 1);
  424 + curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  425 + curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  426 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  427 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  428 + $ret = curl_exec($ch);
  429 + if (false == $ret) {
  430 + $result = curl_error($ch);
  431 + } else {
  432 + $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  433 + if (200 != $rsp) {
  434 + $result = "请求状态 " . $rsp . " " . curl_error($ch);
  435 + } else {
  436 + $result = $ret;
  437 + }
  438 + }
  439 + curl_close($ch);
  440 + return $result;
  441 + }
409 } 442 }