|
@@ -1096,4 +1096,59 @@ class CommonFn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static function httpPost($url,$param,$post_file=false){
|
|
|
+ $oCurl = curl_init();
|
|
|
+ if(stripos($url,"https://")!==FALSE){
|
|
|
+ curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
+ curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
|
|
|
+ }
|
|
|
+ if (is_string($param)) {
|
|
|
+ $strPOST = $param;
|
|
|
+ } else {
|
|
|
+ $aPOST = array();
|
|
|
+ foreach($param as $key=>$val){
|
|
|
+ //$aPOST[] = $key."=".urlencode($val);
|
|
|
+ }
|
|
|
+ $strPOST = join("&", $aPOST);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $this_header = array(
|
|
|
+ "content-type: application/x-www-form-urlencoded;
|
|
|
+ charset=UTF-8"
|
|
|
+ );
|
|
|
+ curl_setopt($oCurl,CURLOPT_HTTPHEADER,$this_header);
|
|
|
+ curl_setopt($oCurl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
|
|
|
+ curl_setopt($oCurl, CURLOPT_POST,true);
|
|
|
+ curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
|
|
|
+ $sContent = curl_exec($oCurl);
|
|
|
+ $aStatus = curl_getinfo($oCurl);
|
|
|
+ curl_close($oCurl);
|
|
|
+ if(intval($aStatus["http_code"])==200){
|
|
|
+ return $sContent;
|
|
|
+ }else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static function sendWxMessage($data){
|
|
|
+ // 环境检查
|
|
|
+ $res = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx9a632fd8918d1a48&secret=1d21b873c19a36b200cf1d0bb1e9aa26');
|
|
|
+
|
|
|
+ $access_token = json_decode($res,true)['access_token'];
|
|
|
+ $result = self::httpPost('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token,$data);
|
|
|
+ if ($result)
|
|
|
+ {
|
|
|
+ $json = json_decode($result,true);
|
|
|
+ if (!$json || !empty($json['errcode']) || $json['errcode']!=0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return $json;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|