chenhao 4 年之前
父節點
當前提交
7a09860274
共有 1 個文件被更改,包括 11 次插入10 次删除
  1. 11 10
      application/api/controller/User.php

+ 11 - 10
application/api/controller/User.php

@@ -156,18 +156,19 @@ class User extends Api
             "Accept:application/json"
         );
         $url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$secret&js_code=$js_code&grant_type=authorization_code";
-        $ch = curl_init();
-        $data = array('user' => 'xxx', 'password' => 'yyy');
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $ch = curl_init();                             //初始化
+//        curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
+        curl_setopt($ch, CURLOPT_URL, $url);           //设置访问的URL
+        curl_setopt($ch, CURLOPT_HEADER, false);       //设置不需要头信息
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//只获取页面内容,但不输出
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-        $result = curl_exec($ch);
-        echo $result;
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+        $str = curl_exec($ch);                         //执行访问,返回结果
+        echo $str;die;
         curl_close($ch);                               //关闭curl,释放资源
-        dump($result);die;
-        $openid = json_decode($result, true);
+        dump($str);die;
+        $openid = json_decode($str, true);
         $data["user_openid"] = $openid["openid"];
 
     }