Пример #1
0
 public function actionCurl()
 {
     $return = CURL::post("api.filmfest.com/site/test-post", "post=aaaa&hehe=bbbbxii");
     echo equal('{"post":"aaaa","hehe":"bbbbxii"}', $return, 'CURL::post');
     $data = CURL::get("api.filmfest.com/site/test-get?get=abcss");
     echo equal('{"get":"abcss"}', $data, 'CURL::get');
 }
Пример #2
0
 public static function post($path, $data = [])
 {
     $query_arr = [];
     foreach ($data as $key => $value) {
         $query_arr[] = $key . '=' . $value;
     }
     $query_str = join('&', $query_arr);
     $url = self::$api_url . '/' . $path;
     return CURL::post($url, $query_str);
 }
Пример #3
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";
             //纪录错误日志
         }
     }
 }
Пример #4
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;
 }
Пример #5
0
 public function _get_weixin_user_info($res)
 {
     $access_token = $res->access_token;
     $openid = $res->openid;
     $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN";
     $userinfo = json_decode(CURL::get($url));
     return $userinfo;
 }