Exemplo n.º 1
0
 function actionLogin()
 {
     $post = Yii::$app->request->post();
     if (trim($post['account']) == '*****@*****.**') {
         if ($post['pwd'] == md5('yxdfjzwj9')) {
             $access_token = md5(time() . 'access_token');
             Cache::set('admin_login', $access_token);
             echo json_encode(['errCode' => 0, 'access_token' => $access_token]);
         } else {
             echo json_encode(['errCode' => 1001, 'errMsg' => '密码输入错误!']);
         }
     } else {
         echo json_encode(['errCode' => 1000, 'errMsg' => '账号输入错误!']);
     }
     return;
 }
Exemplo n.º 2
0
 public function actionGetJsapiTicket()
 {
     $weixin_access_token = Cache::get("weixin_access_token");
     $res = CURL::get("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$weixin_access_token}&type=jsapi");
     $res = json_decode($res);
     echo $res->errcode;
     if (isset($res->errcode) && $res->errcode == 40013) {
         echo "invalid appid";
         return;
         //{"errcode":40013,"errmsg":"invalid appid"}
     }
     if (isset($res->errcode) && $res->errcode == 0) {
         if (Cache::set("jsapi_ticket", $res->ticket)) {
             echo "save jsapi_ticket success";
         } else {
             echo "save jsapi_ticket failed";
             //纪录错误日志
         }
     }
 }
Exemplo n.º 3
0
 public function actionAvatar()
 {
     $weixin_access_token = Cache::get("weixin_access_token");
     $media_id = $this->post["server_id"];
     $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$weixin_access_token}&media_id={$media_id}";
     $res = CURL::get($url);
     // 拿到文件,就是一段二进制流
     $res_info = CURL::getHeader();
     //拿到 http 报文
     $image_type = $res_info['content_type'];
     // 文件类型
     $types = array('image/bmp' => '.bmp', 'image/gif' => '.gif', 'image/jpeg' => '.jpg', 'image/png' => '.png');
     $image_name = $media_id . $types[$image_type];
     $fp = fopen("/alidata/www/filmfest/yii2/frontend/web/img/wechat/" . $image_name, "w");
     if (!$fp) {
         // 			debug("save file error !",'save file error !');
     }
     fwrite($fp, $res);
     fclose($fp);
     $return = json_encode(['image_url' => "img/wechat/" . $image_name]);
     return $return;
 }
Exemplo n.º 4
0
 protected function use_js_sdk()
 {
     $js_sdk = [];
     $js_sdk['jsapi_ticket'] = Cache::get("jsapi_ticket");
     $js_sdk['url'] = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
     $js_sdk['timestamp'] = time();
     $js_sdk['noncestr'] = "codekissyoung" . rand(1, 20111);
     ksort($js_sdk);
     $js_sdk_copy = $js_sdk;
     foreach ($js_sdk_copy as $key => &$value) {
         $value = $key . "=" . $value;
     }
     $signature = implode('&', $js_sdk_copy);
     $signature = sha1($signature);
     $js_sdk['signature'] = $signature;
     Yii::$app->view->params['js_sdk'] = $js_sdk;
 }
Exemplo n.º 5
0
 /**
  * 删除缓存
  */
 public function actionDel()
 {
     $ids = $this->helpGpost('ids', []);
     $message = '';
     $code = '';
     foreach ($ids as $k => $v) {
         if (Cache::del($v)) {
             $message = '删除成功!';
             $code = 'success';
         } else {
             $message = '删除失败!';
         }
     }
     return $this->helpResult(['code' => $code, 'message' => $message, 'data' => '']);
 }