<?php
defined('ReqURL') or define('ReqURL', 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx');
include 'init.php';
class Mloader
{
    private $cache = array();
    public function func($name)
    {
        if (isset($this->cache['func'][$name]))
        {
            return true;
        }
        $file = IA_ROOT . '/addons/evzg_express/function/' . $name . '.func.php';
        if (file_exists($file))
        {
            include $file;
            $this->cache['func'][$name] = true;
            return true;
        }
        trigger_error('Invalid Helper Function /addons/evzg_express/function/' . $name . '.func.php', 256);
        return false;
    }
    public function model($name)
    {
        if (isset($this->cache['model'][$name]))
        {
            return true;
        }
        $file = IA_ROOT . '/addons/evzg_express/model/' . $name . '.mod.php';
        if (file_exists($file))
        {
            include $file;
            $this->cache['model'][$name] = true;
            return true;
        }
        trigger_error('Invalid Model /addons/evzg_express/model/' . $name . '.mod.php', 1024);
        return false;
    }
    public function classs($name)
    {
        if (isset($this->cache['class'][$name]))
        {
            return true;
        }
        $file = IA_ROOT . '/addons/evzg_express/class/' . $name . '.class.php';
        if (file_exists($file))
        {
            include $file;
            $this->cache['class'][$name] = true;
            return true;
        }
        trigger_error('Invalid Class /addons/evzg_express/class/' . $name . '.class.php', 256);
        return false;
    }
}
//独立pc端代码
function mweb($do,$params = array(),$addhost=false){
    global $_W;
    if(empty($do)){
        return false;
    }
    $do="mweb".$do;
    $basic = array('do' =>$do, 'm' => 'evzg_express');
    $params = array_merge($basic, $params);
    $url = murl('entry', $params);
    if ($addhost) {
        $url = $_W['siteroot'] . 'app/' . substr($url, 2);
    }
    return $url;
}
function cweb($do,$params = array(),$addhost=false){
    global $_W;
    if(empty($do)){
        return false;
    }
    $basic = array('do' =>$do, 'a'=>'entry','i'=>$_W['uniacid'],'m' => 'evzg_express');
    $params = array_merge($basic, $params);
    $url = url('site', $params);
    if ($addhost) {
        $url = $_W['siteroot'] . 'web/' . substr($url, 2);
    }
    return $url;
}
function etemplate($filename) {

    global $_W;

    $name = strtolower($this->modulename);

    $defineDir = dirname($this->__define);

    if(defined('IN_SYS')) {

        $source = IA_ROOT . "/web/themes/{$_W['template']}/{$name}/{$filename}.html";

        $compile = IA_ROOT . "/data/tpl/web/{$_W['template']}/{$name}/{$filename}.tpl.php";

        if(!is_file($source)) {

            $source = IA_ROOT . "/web/themes/default/{$name}/{$filename}.html";

        }

        if(!is_file($source)) {

            $source = $defineDir . "/template/{$filename}.html";

        }

        if(!is_file($source)) {

            $source = IA_ROOT . "/web/themes/{$_W['template']}/{$filename}.html";

        }

        if(!is_file($source)) {

            $source = IA_ROOT . "/web/themes/default/{$filename}.html";

        }

    } else {

        $source = IA_ROOT . "/app/themes/{$_W['template']}/{$name}/{$filename}.html";

        $compile = IA_ROOT . "/data/tpl/app/{$_W['template']}/{$name}/{$filename}.tpl.php";

        if(!is_file($source)) {

            $source = IA_ROOT . "/app/themes/default/{$name}/{$filename}.html";

        }

        if(!is_file($source)) {

            $source = $defineDir . "/template/mobile/{$filename}.html";

        }

        if(!is_file($source)) {

            $source = IA_ROOT . "/app/themes/{$_W['template']}/{$filename}.html";

        }

        if(!is_file($source)) {

            if (in_array($filename, array('header', 'footer', 'slide', 'toolbar', 'message'))) {

                $source = IA_ROOT . "/app/themes/default/common/{$filename}.html";

            } else {

                $source = IA_ROOT . "/app/themes/default/{$filename}.html";

            }

        }

    }



    if(!is_file($source)) {

        exit("Error: template source '{$filename}' is not exist!");

    }

    $paths = pathinfo($compile);

    $compile = str_replace($paths['filename'], $_W['uniacid'] . '_' . $paths['filename'], $compile);

    if (DEVELOPMENT || !is_file($compile) || filemtime($source) > filemtime($compile)) {

        template_compile($source, $compile, true);

    }

    return $compile;

}
function is_weixin(){

    if (strpos($_SERVER['HTTP_USER_AGENT'],'MicroMessenger')!== false) {
        return true;
    }
    return false;

}
function cmurl($segment, $params = array(), $addhost = false)
{
	global $_W;
	list($ctrl, $ac, $op, $ta) = explode('/', $segment);
	$basic = array('ctrl' => $ctrl, 'ac' => $ac, 'op' => $op, 'ta' => $ta, 'do' => 'mobile', 'm' => 'evzg_express');
	$params = array_merge($basic, $params);
	$url = murl('entry', $params);

	if ($addhost) {
		$url = $_W['siteroot'] . 'app/' . substr($url, 2);
	}

	return $url;
}
function build_order_no()
{
    /* 选择一个随机的方案 */
    mt_srand((double) microtime() * 1000000);
    $order_no = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
    $orderno = substr($order_no,3,2);
    return $orderno;
}
function order_no()
{
    /* 选择一个随机的方案 */
    mt_srand((double) microtime() * 1000000);
    $order_no = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);

    return $order_no;
}
function getEvgShop($expressn){
    $setting = getSetting();
    $kd = new Kd($setting['uid'], $setting['apikey']);
    $logisticResult = $kd->getOrderTracesByJson($expressn);
    $logisticResult =json_decode($logisticResult,true);
    $data = ['shippercode'=>$logisticResult['Shippers'][0]['ShipperCode'],'shippername'=>$logisticResult['Shippers'][0]['ShipperName']];
    //die($data);
    if($logisticResult['Success']){
        return $data;
    }else{
        return false;
    }
}
/**
 * 打印快递单子
 * */
 function printEvg($orderid,$type='kdn'){
     global $_W;
     if($type=='kdn'){
         $order = pdo_get("evzg_express_expressorder",array('id'=>$orderid,'status'=>2));
         if(empty($order)){
             return 'ss';
         }
         $eorder = [];
         $eorder["ShipperCode"] = $order['shipperCode'];
         $eorder["OrderCode"] = $order['orderno'];
         $eorder["PayType"] = 1;
         $eorder["ExpType"] = 1;

         $sender = [];
         $sender["Name"] = $order['name'];
         $sender["Mobile"] = $order['mobile'];
         $sender["ProvinceName"] = $order['name'];
         $address = explode(" ",$order['address']);
         if(is_array($address)&&count($address)>1){
           $sender["CityName"] = $address[0];
           $sender["ExpAreaName"] = $address[1];
           $sender["Address"] = $address[2];
         }
         $receiver = [];
         $eorder['IsReturnPrintTemplate'] =1;
         $receiver["Name"] = $order['sname'];
         $receiver["Mobile"] = $order['smobile'];
         $receiver["ProvinceName"] = $order['sname'];
         $saddress = explode(" ",$order['saddress']);
         if(is_array($saddress)&&count($saddress)>1){
             $receiver["CityName"] = $saddress[0];
             $receiver["ExpAreaName"] = $saddress[1];
             $receiver["Address"] = $saddress[2];
         }
         $commodityOne = [];
         $commodityOne["GoodsName"] = $order['goods'];
         $commodity = [];
         $commodity[] = $commodityOne;

         $eorder["Sender"] = $sender;
         $eorder["Receiver"] = $receiver;
         $eorder["Commodity"] = $commodity;
         //调用电子面单
         $jsonParam = json_encode($eorder, JSON_UNESCAPED_UNICODE);
         $setting = getSetting();
         $kd = new Kd($setting['uid'], $setting['apikey']);
         $logisticResult = $kd->submitEOrder($jsonParam);
         $result = json_decode($logisticResult, true);
         if($result['ResultCode']==100){
             pdo_update("evzg_express_expressorder",array('expresscode'=>$result['Order']['ShipperCode'],'expresssn'=>$result['Order']['LogisticCode']),array('id'=>$orderid));
             pdo_insert("evzg_express_print",array('uniacid'=>$_W['uniacid'],'oid'=>$orderid,'uniquerRequestNumber'=>$order['orderno'],'resultCode'=>$result['ResultCode'],'reason'=>$result['Reason'],'printTemplate'=>$result['PrintTemplate'],'createtime'=>time()));
             return true;
         }else{
             pdo_insert("evzg_express_print",array('uniacid'=>$_W['uniacid'],'oid'=>$orderid,'uniquerRequestNumber'=>$result['UniquerRequestNumber'],'resultCode'=>$result['ResultCode'],'reason'=>$result['Reason'],'printTemplate'=>"",'createtime'=>time()));

             return false;
         }
     }

 }
/***
 * 获取快递接口
 *
 * */
function getEvgLink($expressn,$exprescode){
    $setting = getSetting();
    $kd = new Kd($setting['uid'], $setting['apikey']);
    $data = $kd->getTracesByJson($exprescode, $expressn);
    $data = json_decode($data,true);
    if($data['Success']){
        return $data['Traces'];
    }else{
        return false;
    }
}
function getmedia($access_token,$media_id,$foldername){
    $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=".$access_token."&media_id=".$media_id;
    if (!file_exists("../attachment/images/".$foldername)) {
        mkdir("../attachment/images/".$foldername, 0777, true);
    }
    $targetName = '../attachment/images/'.$foldername.'/'.date('YmdHis').rand(1000,9999).'.jpg';
    $ch = curl_init($url); // 初始化
    $fp = fopen($targetName, 'wb'); // 打开写入
    curl_setopt($ch, CURLOPT_FILE, $fp); // 设置输出文件的位置，值是一个资源类型
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    $targetName = str_replace("../attachment/","",$targetName);
    return $targetName;
}

function get_shopname($sid)
{
    global $_W;
    $data = pdo_fetch("SELECT * FROM " . tablename('evzg_express_shop') . ' WHERE uniacid = :uniacid AND id = :id', array(
        ':uniacid' => $_W['uniacid'],
        ':id' => $sid,
    ));
    if(empty($data)){
        $data['name'] ="暂无绑定服务商店";
    }
    return $data['name'];
}
//获取小区条数
function get_community($cid)
{
    global $_W;
    $data = pdo_fetch("SELECT * FROM " . tablename('evzg_express_community') . ' WHERE uniacid = :uniacid AND id= :id ', array(
        ':uniacid' => $_W['uniacid'],
        ':id' => $cid,
    ));
    if(empty($data)){
        $data['title'] ="暂无绑定小区";
    }
    return $data['title'];
}
function generate_code($length = 6) {
    $min = pow(10 , ($length - 1));
    $max = pow(10, $length) - 1;
    return rand($min, $max);
}
//获取小区条数
function get_trends()
{
    global $_W;
    $data = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('evzg_express_trends') . ' WHERE uniacid = :uniacid AND openid= :openid ', array(
        ':uniacid' => $_W['uniacid'],
        ':openid' => $_W['openid'],
    ));
    if(empty($data)){
        return 0;
    }
    return $data;
}
/**
* 创建永久二维码
* @date: 2017年12月16日 下午11:36:49
* @author: Administrator
* @param: qrid 二维码参数
* @return: false OR 二维码ticket
*/
function create_ticket($qrid){
    global $_W;
   load()->model('account');
   $uniacccount = WeAccount::create($_W['uniacid']);
   $barcode['action_info']['scene']['scene_str'] = $qrid;
   $barcode['action_name'] = 'QR_LIMIT_STR_SCENE';
   $result = $uniacccount->barCodeCreateFixed($barcode);
   if($result){
       return $result;
   }else {
       return false;
   }
}
//
function trendExpre($exprenoid){
    global $_W;
    $data = array();
    load()->func('communication');
    $result = pdo_get("evzg_express_trends",array('id'=>$exprenoid,'status'=>1));
    if(!empty($result)){
        $data['siteroot'] =$_W['siteroot'];
        $data['expresssn'] =$result['expresssn'];
        $data['expresscode'] =$result['expresscode'];
        $data['expressshop'] =$result['expressshop'];
        $data['uniacid'] = $_W['uniacid'];
        $url = "http://www.qycompany.cn/api.php/trend/take";
        $response = ihttp_request($url, $data);
    }else{
        return false;
    }


}
/**
* 发送信息
* @date: 2017年12月17日 上午2:59:01
* @author: Administrator
* @param: $GLOBALS
* @return:
*/
function sendMsg($data){
     global $_W, $_GPC;
     load()->classs('weixin.account');
     $account_api = WeAccount::create();
     $account_api->clearAccessToken();
     $access_token = $account_api->getAccessToken();
     load()->func('communication');
     $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
     $response = ihttp_request($url, $data);
     if (is_error($response)) {
    	message("访问公众平台接口失败, 错误: {$response['message']}",referer(),"error");
     }
     $result = json_decode($response['content'], true);
     if (empty($result)) {
    	message("接口调用失败, 元数据: {$response['meta']}",referer(),"error");
     } elseif (!empty($result['errcode'])) {
    	message( "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},信息详情：{$this->error_code($result['errcode'])}",referer(),"error");
     }
	 return true;
}
/**
 * 发送信息 并且记录发送记录
 * @date: 2017年12月17日 上午2:59:01
 * @author: Administrator
 * @param: $GLOBALS
 * @return:
 */
function sendMsgTpl($data,$log=array()){
    global $_W;
    load()->classs('weixin.account');
    $account_api = WeAccount::create();
    $account_api->clearAccessToken();
    $access_token = $account_api->getAccessToken();
    if(empty($data)){
        return  false;
    }
    $sendContent = array();
    if(!empty($data['data']['first'])){
        $sendContent['first']['value']=$data['data']['first'];
        $sendContent['first']['color']='#FF0000';
    }
    if(!empty($data['data']['keyword1'])){
        $sendContent['keyword1']['value']=$data['data']['keyword1'];
    }
    if(!empty($data['data']['keyword2'])){
        $sendContent['keyword2']['value']=$data['data']['keyword2'];
    }

    if(!empty($data['data']['keyword3'])){
        $sendContent['keyword3']['value']=$data['data']['keyword3'];
        $sendContent['keyword3']['color']='#FF0000';
    }
    if(!empty($data['data']['keyword4'])){
        $sendContent['keyword4']['value']=$data['data']['keyword4'];
        $sendContent['keyword4']['color']='#FF0000';
    }
    if(!empty($data['remark'])){
        $sendContent['remark']['value']=$data['remark'];
        $sendContent['remark']['color']='#FF0000';
    }
    $template = array(
        "touser" => $data['openid'],
        "template_id" => $data['template_id'],
        "url" => $data['url'],
        "topcolor" => "#FF0000",
        "data" => $sendContent
    );
    $tpl =  urldecode(json_encode($template));
    load()->func('communication');
    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
    $response = ihttp_request($url, $tpl);
    if (is_error($response)) {
        message("访问公众平台接口失败, 错误: {$response['message']}",referer(),"error");
    }
    $result = json_decode($response['content'], true);
    $tplLog ='';
    if (empty($result)) {
        $tplLog = "接口调用失败, 原数据: {$response['meta']}";

    } elseif (!empty($result['errcode'])) {
         $tplLog = "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},信息详情";
    }else{
        $log['status'] = 1;
    }
    if(!empty($log)){
        $log['oid'] = $log['id'];
        $log['sid'] = $log['sid'];
        if(empty($log['openid'])||!isset($log['openid'])){
            $log['openid'] = $data['openid'];
        }


        if(empty($log['operator'])){
            $log['operator'] = '系统';
        }
        if(empty($log['content'])){
            $log['content'] = $data['data']['first'];
        }
        $log['addtime']=time();
        $log['msg'] = $tplLog;
        $log['type'] = 2;

        msgLog($log);
       // var_dump($log);die();
    }
    if(!empty($tplLog)){
        return $tplLog;
    }
    return true;
}
/**
 * 获取参数设置
 * */
function getSetting(){
    global $_W;
    $settings = pdo_fetch("SELECT * FROM ".tablename('uni_account_modules')." WHERE module = :module AND uniacid = :uniacid", array(':module' => 'evzg_express', ':uniacid' => $_W['uniacid']));

    $setting = iunserializer($settings['settings']);
   // exit(json_encode($settings));
    return $setting;
}
/**
* 发送订单消息通知
* @date: 2018年1月14日 上午1:04:52
* @author: 闵晓天 QQ416883181
* @param: $GLOBALS
* @return: true or false
*/
function sendOrderMsg($openid,$data,$templateid){
    global $_W, $_GPC;
    if(!empty($openid)){
       return false;
    }
    $template = array(
        "touser" => $openid,
        "template_id" => $templateid,
        "url" => $_W['siteroot'] . 'app/' . $this->createMobileUrl('express'),
        "topcolor" => "#FF0000",
        "data" => array(
            'first' => array(
                'value' => urlencode("您好，你的快递{$data['expresssn']}已经到达{$data['name']}门店" . "\\n"),
                'color' => "#743A3A"
                    ),
                    'keyword1' => array(
                        'value' => urlencode($data['orderno']),
                        'color' => '#000000'
                    ),
                    'keyword2' => array(
                        'value' => urlencode($data['expresssn']),
                        'color' => '#EF4F4F'
                    ),
                    'keyword3' => array(
                        'value' => urlencode($data['name']),
                        'color' => '#EF4F4F'
                    ),
                    'keyword4' => array(
                        'value' => urlencode($data['mobile']),
                        'color' => '#EF4F4F'
                    ),
                    'remark' => array(
                        'value' => urlencode("\\n感谢您的使用"),
                        'color' => "#01579b"
                    )
        )
    );
   $result = sendMsg(urldecode(json_encode($template)));
   return $result;
}

function sendSms($mobile,$TemplateCode,$TemplateParam,$settings,$log=array()) {
       mload()->classs('signaturehelper');
       mload()->model('shop');
       mload()->model('sms');
       $sid = $log['sid'];
       $shop_set = shop_get_set();
       if($shop_set['smsprice']>0&&!empty($log['sid'])){
          $smsnum = shop_get_smsnum($sid);
          if(empty($smsnum)){
              if(!empty($log)){
                  $log['oid'] = $log['id'];
                  $log['sid'] = $log['sid'];
                  if(empty($log['openid'])){
                      $log['openid'] = $mobile;
                  }
                  if(empty($log['operator'])){
                      $log['operator'] = '系统';
                  }
                  $log['content'] = "阿里大鱼：商户余额不足";
                  $log['addtime']=time();
                  $log['msg'] = "阿里大鱼：商户余额不足";
                  $log['type'] = 1;
                  msgLog($log);
              }
             return false;
          }
        }
        $params = array ();

        // *** 需用户填写部分 ***

        // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
        $accessKeyId = $settings['dayu']['dayu_appkey'];
        $accessKeySecret = $settings['dayu']['dayu_secretkey'];

        // fixme 必填: 短信接收号码
        $params["PhoneNumbers"] = $mobile;

        // fixme 必填: 短信签名，应严格按"签名名称"填写，请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
        $params["SignName"] = $settings['dayu']['dayu_sign'];

        // fixme 必填: 短信模板Code，应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
        $params["TemplateCode"] = $TemplateCode;

        // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
        $params['TemplateParam'] = $TemplateParam;

        // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
        if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
            $params["TemplateParam"] = json_encode($params["TemplateParam"]);
        }
        // 初始化SignatureHelper实例用于设置参数，签名以及发送请求
        $helper = new SignatureHelper();

        // 此处可能会抛出异常，注意catch
        $content = $helper->request(
            $accessKeyId,
            $accessKeySecret,
            "dysmsapi.aliyuncs.com",
            array_merge($params, array(
                "RegionId" => "cn-hangzhou",
                "Action" => "SendSms",
                "Version" => "2017-05-25",
            ))
        );
      $contents = json_decode(json_encode($content),true);


     if(!empty($log)){
        $log['oid'] = $log['id'];
        $log['sid'] = $log['sid'];
        if(empty($log['openid'])){
            $log['openid'] = $mobile;
        }
        if(empty($log['operator'])){
            $log['operator'] = '系统';
        }
        if(empty($log['content'])){
            $log['content'] = "阿里大鱼：".$params["TemplateParam"];
        }

        $log['addtime']=time();
        $log['msg'] = json_encode($content);
        $log['type'] = 1;
        $log['mobile'] = $mobile;
        $logid = msgLog($log);

      }
      if($contents['Message']=='OK'){
          $log['status'] =1;
          if($shop_set['smsprice']>0&&!empty($log['sid'])){
              sms_send_success($logid,$settings);
          }
      }
       return $content;
}
/**
* 聚合短信发送
* @date: 2018年1月20日 下午8:31:22
* @author: Administrator
* @param: $GLOBALS
* @return:
*/
function juHeSms($key,$mobile,$tpl_id,$tpl_value,$log=array()){
    $sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL

    $smsConf = array(
        'key'   => $key, //您申请的APPKEY
        'mobile'    => $mobile, //接受短信的用户手机号码
        'tpl_id'    => $tpl_id, //您申请的短信模板ID，根据实际情况修改
        'tpl_value' =>$tpl_value //您设置的模板变量，根据实际情况修改
    );

    $content = juhecurl($sendUrl,$smsConf,1); //请求发送短信
    if(!empty($log)){
        $log['oid'] = $log['id'];
        $log['sid'] = $log['sid'];
        if(empty($log['openid'])){
            $log['openid'] = $mobile;
        }
        if(empty($log['operator'])){
            $log['operator'] = '系统';
        }
        if(empty($log['content'])){
            $log['content'] = "聚合短信：".$tpl_value;
        }
        $result = json_decode($content,true);
        $error_code = $result['error_code'];
        $log['addtime']=time();
        $log['msg'] = $error_code;
        $log['type'] = 1;
        msgLog($log);
    }
    if($content){
        $result = json_decode($content,true);
        $error_code = $result['error_code'];
        if($error_code == 0){
            //状态为0，说明短信发送成功
           return true;
        }else{
            //状态非0，说明失败
            return false;
        }
    }else{
        //返回内容异常，以下可根据业务逻辑自行修改
        return false;
    }
}
/**
 * 请求接口返回内容
 * @param  string $url [请求的URL地址]
 * @param  string $params [请求的参数]
 * @param  int $ipost [是否采用POST形式]
 * @return  string
 */
function juhecurl($url,$params=false,$ispost=0){
    $httpInfo = array();
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
    curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
    curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
    if( $ispost )
    {
        curl_setopt( $ch , CURLOPT_POST , true );
        curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
        curl_setopt( $ch , CURLOPT_URL , $url );
    }
    else
    {
        if($params){
            curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
        }else{
            curl_setopt( $ch , CURLOPT_URL , $url);
        }
    }
    $response = curl_exec( $ch );
    if ($response === FALSE) {
        //echo "cURL Error: " . curl_error($ch);
        return false;
    }
    $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
    $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
    curl_close( $ch );
    return $response;
}
/**
 * 发送记录log
 * @date: 2018年1月14日 上午1:04:52
 * @author: 闵晓天 QQ416883181
 * @param: $GLOBALS
 * @return: true or false
 */
 function msgLog($data){
    global $_W;
    if(empty($data)){
      return false;
    }
    $data['uniacid'] = $_W['uniacid'];
    pdo_insert("evzg_express_log",$data);
    $id = pdo_insertid();
    return $id;
 }
