quguofeng %!s(int64=2) %!d(string=hai) anos
pai
achega
ea29a1d391
Modificáronse 2 ficheiros con 44 adicións e 2 borrados
  1. 8 1
      application/api/controller/Login.php
  2. 36 1
      application/common.php

+ 8 - 1
application/api/controller/Login.php

@@ -30,6 +30,13 @@ class Login extends Base
         $user_info = $get_info_obj->get_user_info($user_token);
         var_dump($user_info);exit();
     }
-
+    public function test(){
+        $code = input('code');
+        $res = requestGet('https://api.weixin.qq.com/cgi-bin/token?appid=wx432ce2635b52757f&secret=662eaf0bd433afa8b3b2498f625b6e07&code='.$code.'&grant_type=client_credential');
+        $res = json_decode($res,true);
+        $user_info = requestPost('https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token='.$res['access_token'],json_encode(array('code'=>$code)));
+        $user_info = json_decode($user_info,true);
+        var_dump($user_info);exit();
+    }
 
 }

+ 36 - 1
application/common.php

@@ -21,7 +21,42 @@ function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
     }
     return $day;
 }
-
+function requestPost($url , $post_data = array() ){
+    // 1. 初始化一个cURL会话
+    $ch = curl_init();
+    // 2. 设置请求选项, 包括具体的url
+    curl_setopt($ch, CURLOPT_URL, $url);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+    // 设置请求为post类型
+    curl_setopt($ch, CURLOPT_POST, 1);
+    // 添加post数据到请求中
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
+    curl_setopt($ch, CURLOPT_HEADER, 0);
+    // 3. 执行一个cURL会话并且获取相关回复
+    $response = curl_exec($ch);
+    // 4. 释放cURL句柄,关闭一个cURL会话
+    curl_close($ch);
+    return $response;
+}
+/**
+ * get请求
+ * @param $url
+ * @param string $msg
+ * @return mixed
+ */
+function requestGet($url , $msg = ''){
+    // 1. 初始化一个cURL会话
+    $ch = curl_init();
+    //设置选项,包括URL
+    curl_setopt($ch, CURLOPT_URL, $url);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+    curl_setopt($ch, CURLOPT_HEADER, 0);
+    //执行并获取HTML文档内容
+    $response = curl_exec($ch);
+    // 4. 释放cURL句柄,关闭一个cURL会话
+    curl_close($ch);
+    return $response;
+}
 // 获取模板区域
 function get_city_area()
 {