public function index()
 {
     $appid = 'wx107878bd9006d5d0';
     $appsecret = 'd4624c36b6795d1d99dcf0547af5443d';
     $weixin = new Weixin($appid, $appsecret);
     //        $data['appid']=$appid;
     //        $data['create_time'] = $weixin->getCreatetime();
     //        $data['nonceStr'] = NONCESTR;
     //        $data['signature'] = $weixin->getWxSignature();
     //
     //        $this->data=$data;
     $sign = new \Think\Jssdk($appid, $appsecret);
     $signPackage = $sign->GetSignPackage();
     //print_r($signPackage);
     $this->sign = $signPackage;
     //        var_dump($data);
     $this->display();
 }
 public function apply()
 {
     $this->isauth();
     if (IS_POST) {
         $Apply = M('Apply');
         $map['openid'] = session('openid');
         if ($Apply->where($map)->find()) {
             $this->ajaxReturn(array('status' => 0, 'info' => '您已报名,请勿重复操作!'));
             exit;
         }
         if (I('name') == '') {
             $this->ajaxReturn(array('status' => 0, 'info' => '请输入您的姓名!'));
             exit;
         }
         if (I('telphone') == '') {
             $this->ajaxReturn(array('status' => 0, 'info' => '请输入您的联系电话!'));
             exit;
         }
         if (I('content') == '') {
             $this->ajaxReturn(array('status' => 0, 'info' => '请输入描述!'));
             exit;
         }
         $data['openid'] = session('openid');
         $data['name'] = I('name');
         $data['phone'] = I('telphone');
         $data['content'] = I('content');
         $ids = I('serverids');
         $serverid = explode(',', $ids);
         $access_token = session('curtoken');
         $now = time();
         $timepath = date('Y-m-d', $now);
         if (!file_exists("Uploads/Picture/{$timepath}/")) {
             if (mkdir("Uploads/Picture/{$timepath}/")) {
                 $path = "Uploads/Picture/{$timepath}/";
             } else {
                 $path = "Uploads/Picture/";
             }
         } else {
             $path = "Uploads/Picture/{$timepath}/";
         }
         foreach ($serverid as $k => $v) {
             $mediaid = $v;
             $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaid}";
             $fileInfo = $this->downloadWeixinFile($url);
             $filename = $path . rand(100000, 999999) . $now . $k . ".jpg";
             $arr[] = $this->saveWeixinFile($filename, $fileInfo["body"]);
             //$arr[] = (array)json_decode(https_request('http://file.api.weixin.qq.com/cgi-bin/media/get?access_token='.session('curtoken').'&media_id='.$v));
         }
         $data['pics'] = implode(',', $arr);
         $data['create_time'] = $now;
         if ($Apply->add($data)) {
             $this->ajaxReturn(array('status' => 1, 'info' => '报名成功!'));
             exit;
         } else {
             $this->ajaxReturn(array('status' => 0, 'info' => '报名失败,请与管理员联系!'));
             exit;
         }
     } else {
         $sign = new \Think\Jssdk('wxb03abb1444f7308f', '4ee5b123dc62e93e3778f7900062c823');
         $signPackage = $sign->GetSignPackage();
         $this->sign = $signPackage;
         $this->display();
     }
 }