<?php
/**
  * @class 微信API
  * @author soul 2022/5/27
  */
class OthWechatEy
{
	//EY的登录实例标识
	public $eywid = '';

	//机器人的接口
	public function getWxApi($path, $data = []){
		$url = mvc::$cfg['EYBOT']['api'].$path;
		if(!empty($this->eywid) && empty($data['wId'])) $data['wId'] = $this->eywid;
		$headers = ['Authorization: '.mvc::$cfg['EYBOT']['auth'],'Content-Type: application/json'];
		if(is_array($data)) $data = json_encode($data);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		$ssl = substr($url, 0, 8) == "https://" ? true : false;
        if($ssl){
           curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// 信任任何证书
           curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);// 检查证书中是否设置域名
        }
		$html = curl_exec($ch);
		//echo $url.'=>'.$data.'=>'.$html;
		LibFc::logs($_GET['wrt_id'].':'.$url.'=>'.$data.'=>'.$html);
		$response = json_decode($html ,true);
		if(!isset($response['code']) || $response['code'] != "1000"){
			LibFc::logs($data['wId'].'接口异常=>'.json_encode(['post'=>$data, 'html'=>$html], JSON_UNESCAPED_UNICODE));
			if(stripos($html, '等待验证') === false)
				LibFc::ReturnData(false, 'EYAPI 接口异常'.$data['wId'].'=>'.$html);
		}
		return $response;
	}
}