コード例 #1
0
 /**
  * 发布推送的信息到所有关注用户
  */
 public function send()
 {
     $togroup = I("togroup");
     //生成需要发送的数据
     is_array($model) || ($model = $this->getModel($model));
     !empty($ids) || ($ids = I('id'));
     !empty($ids) || ($ids = array_unique((array) I('ids', 0)));
     !empty($ids) || $this->error('请选择要操作的数据!');
     $Model = M(get_table_name($model['id']));
     $map['id'] = array('in', $ids);
     // 插件里的操作自动加上Token限制
     $token = get_token();
     if (defined('ADDON_PUBLIC_PATH') && !empty($token)) {
         $map['token'] = $token;
     }
     $sendlists = $Model->where($map)->order('sort asc')->select();
     if (!$sendlists) {
         $this->error('请选择要操作的数据!');
     }
     foreach ($sendlists as $key => $value) {
         $newdata['articles'][] = array("title" => $value['title'], "description" => $value['description'], "url" => $value['url'], "picurl" => $value['picurl']);
     }
     $senddata = array('touser' => '', 'msgtype' => 'news', 'news' => $newdata);
     $mapinfo['token'] = $token;
     $info = M('member_public')->where($mapinfo)->find();
     $this->assign('info', $info);
     $options = array('token' => 'weiphp', 'appid' => $info['appid'], 'appsecret' => $info['secret']);
     $weObj = new Wechat($options);
     $userlist = $weObj->getUserList();
     $oksum = 0;
     foreach ($userlist['data']['openid'] as $key => $value) {
         $senddata['touser'] = $value;
         $result = $weObj->sendCustomMessage($senddata);
         if ($result) {
             $oksum++;
         }
     }
     $this->success('消息群发完成,共计' . $oksum . '用户接收消息。');
 }
コード例 #2
0
 /**
  * 上传图片到公众平台
  */
 public function createthumbID()
 {
     $map['token'] = get_token();
     $info = M('member_public')->where($map)->find();
     $this->assign('info', $info);
     $options = array('token' => 'weiphp', 'appid' => $info['appid'], 'appsecret' => $info['secret']);
     $weObj = new Wechat($options);
     $accessToken = $weObj->checkAuth($info['appid'], $info['secret']);
     $imgid = I('thumbimgid');
     $imgpath = get_cover($imgid, 'path');
     $file = realpath(substr($imgpath, 1));
     //要上传的文件
     $fields['media'] = '@' . $file;
     $ch = curl_init();
     $apipath = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={$accessToken}&type=image";
     curl_setopt($ch, CURLOPT_URL, $apipath);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     $sContent = curl_exec($ch);
     $sContent1 = $sContent;
     $aStatus = curl_getinfo($ch);
     curl_close($ch);
 }