public function batch_insert_openid($openids) { $openid = []; foreach ($openids as $k => $v) { $data = []; $data[]['openid'] = $v; $openid = array_merge($openid, $data); } Openid::insert($openid); }
public function index() { $url = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=" . $this->return_token(); $result = Openid::get()->toArray(); foreach ($result as $k => $v) { $openid[] = $v['openid']; } $data = ['touser' => $openid, 'mpnews' => ['media_id' => $this->media_id], 'msgtype' => 'mpnews']; $re = $this->sendPost($url, json_encode($data)); var_dump($re); }
public function push_openids() { $url = "https://api.weixin.qq.com/cgi-bin/message/send?access_token=" . $this->token; $news = ['articles' => [['title' => '联想服务周末加班,坚持为您升Win10', 'description' => '联想服务周末加班,坚持为您升Win10', 'url' => 'http://mp.weixin.qq.com/s?__biz=MjM5MjAyNzE4MA==&mid=280755695&idx=1&sn=b6425132cf991476e6e8fdd2551e19a6#rd', 'picurl' => 'http://mmbiz.qpic.cn/mmbiz/K1QTs69PnJTPX01VHWKbPibeESz4uatMdcXbUBlVTqNe0FbbVO81kMlaTgo92KN2piaVLAp797iat8hDm50651m8A/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1']]]; $page = 1; $pagesize = 10000; $size = ($page - 1) * $pagesize; $openids = Openid::skip(1500)->take(8500)->get()->toArray(); foreach ($openids as $k => $v) { $data = ['touser' => $v['openid'], 'msgtype' => 'news', 'news' => $news]; $data = json_encode($data, JSON_UNESCAPED_UNICODE); $result = $this->sendPost($url, $data); var_dump($v['id'] . $result); } }