DESKTOP-2STQMTS\Administrator há 3 anos atrás
pai
commit
4fa235234a
1 ficheiros alterados com 29 adições e 0 exclusões
  1. 29 0
      app/Servers/WeChat/WeixinServer.php

+ 29 - 0
app/Servers/WeChat/WeixinServer.php

@@ -97,4 +97,33 @@ class WeixinServer
         }
         exit();
     }
+
+    /**
+     * @param $url
+     * @param string $type 请求方式
+     * @param string $data 数据 数组格式
+     * @return mixed
+     */
+    protected function sendRequest($url, $type = 'get', $data = '')
+    {
+
+        $ch = curl_init();
+        if ($type == 'get' && $data) {
+            $url = $url . '?' . http_build_query($data);
+        }
+        curl_setopt($ch, CURLOPT_URL, $url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        $head = array('User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36');
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
+        if ($type == 'post') {
+            curl_setopt($ch, CURLOPT_POST, TRUE);//post请求
+            $data = json_encode($data, JSON_UNESCAPED_UNICODE);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置传递的参数
+        }
+        $request = curl_exec($ch);
+        curl_close($ch);
+        return $request;
+    }
 }