Ejemplo n.º 1
0
 private function getAccessToken()
 {
     load()->func('communication');
     load()->classs('weixin.account');
     $accObj = new WeixinAccount();
     $access_token = $accObj->fetch_available_token();
     return $access_token;
 }
Ejemplo n.º 2
0
 public function getAccessToken()
 {
     global $_W;
     load()->classs('weixin.account');
     $accObj = new WeixinAccount();
     $access_token = $accObj->fetch_available_token();
     return $access_token;
 }
Ejemplo n.º 3
0
 public function doMobileAdd()
 {
     global $_W, $_GPC;
     load()->func('file');
     load()->func('tpl');
     $categorys = pdo_fetchall("SELECT * FROM" . tablename($this->table_category) . "WHERE weid='{$_W['weid']}'");
     $data = array('weid' => $_W['weid'], 'openid' => $_W['fans']['from_user'], 'title' => $_GPC['title'], 'rolex' => $_GPC['rolex'], 'price' => $_GPC['price'], 'realname' => $_GPC['realname'], 'sex' => $_GPC['sex'], 'mobile' => $_GPC['mobile'], 'description' => $_GPC['description'], 'createtime' => TIMESTAMP, 'pcate' => $_GPC['pcate'], 'status' => 0, 'thumb1' => $_GPC['thumb1'], 'thumb2' => $_GPC['thumb2'], 'thumb3' => $_GPC['thumb3']);
     if (!empty($_GPC['id'])) {
         $good = pdo_fetch("SELECT * FROM" . tablename($this->table_goods) . "WHERE id='{$_GPC['id']}'");
     }
     if (!empty($_GPC['image'])) {
         load()->classs('weixin.account');
         $accObj = new WeixinAccount();
         $access_token = $accObj->fetch_available_token();
         $images = explode(",", $_GPC['image']);
         foreach ($images as $key => $image) {
             //下载图片
             $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$image}";
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_NOBODY, 0);
             //只取body头
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $package = curl_exec($ch);
             $httpinfo = curl_getinfo($ch);
             curl_close($ch);
             $fileInfo = array_merge(array('header' => $httpinfo), array('body' => $package));
             $rand = rand(100, 999);
             $filename = date("YmdHis") . $rand . ".jpg";
             $filepath = ATTACHMENT_ROOT . "/images/thinkidea_secondmarket/" . $filename;
             $filecontent = $fileInfo["body"];
             $dir_name = ATTACHMENT_ROOT . "/images/thinkidea_secondmarket";
             if (!is_dir($dir_name)) {
                 $dir = mkdir($dir_name, 0777, true);
             }
             if (false !== $dir) {
                 $local_file = fopen($filepath, 'w');
                 if (false !== $local_file) {
                     if (false !== fwrite($local_file, $filecontent)) {
                         fclose($local_file);
                         $info['img'] = "/images/thinkidea_secondmarket/" . $filename;
                         if ($key <= 2) {
                             $data['thumb' . ($key + 1)] = $info['img'];
                         }
                     }
                 } else {
                     message("图片上传失败,请联系管理员!", "javascript:WeixinJSBridge.call('closeWindow');", "error");
                 }
             } else {
                 message("目录创建失败!", "javascript:WeixinJSBridge.call('closeWindow');", "error");
             }
         }
     }
     if ($_W['ispost']) {
         if (empty($_GPC['id'])) {
             pdo_insert($this->table_goods, $data);
             message('发布成功', $this->createMobileUrl('list'), 'success');
         } else {
             pdo_update($this->table_goods, $data, array('id' => $_GPC['id']));
             message('更新成功', $this->createMobileUrl('list'), 'success');
         }
     }
     include $this->template('add');
 }