aogg
7/11/2019 - 7:23 AM

微擎相关方法

微擎相关方法

<?php
if (!function_exists('apiUrl')) {
	/**
	 * ewei_shopv2_api的地址
	 *
	 * @param $do
	 * @param string $string
	 * @param int $i
	 * @return string
	 */
	function apiUrl($do, $string = '', $i = null){
		global $_W, $_GPC;

		$i = isset($i) ? $i : (isset($_GPC['i']) ? $_GPC['i'] : 2);

		return $_W['host_url'] . "/app/ewei_shopv2_api.php?i={$i}&r={$do}" . $string;
	}
}
<?php
if (!function_exists('ifTest')) {
	/**
	 * 判断是否测试环境
	 *
	 * @return string
	 */
	function ifTest(){
		global $_W;

		return $_W['config']['db']['master']['host'] === '123.207.238.177' ||
			gethostbyname($_SERVER["SERVER_NAME"]) === '123.207.238.177';
	}
}
<?php
if (!function_exists('includeCommonFile')) {
	/**
	 * psr-0的加载app/common下的文件
	 *
	 * @param $filePath
	 */
	function includeCommonFile($filePath){
		global $_W, $_GPC;

		include_once IA_ROOT . '/app/common/' . $filePath;
	}
}
<?php
if (!function_exists('gpcJson')) {
	/**
	 * 根据key获取json参数
	 *
	 * @param $gpcKey
	 * @return mixed
	 */
	function gpcJson($gpcKey){
		global $_W, $_GPC;
		$value = json_decode(htmlspecialchars_decode(isset($_GPC[$gpcKey])?$_GPC[$gpcKey]:'', ENT_QUOTES), true);

		if (json_last_error()){
			return error(-1, json_last_error_msg());
		}

		return $value;
	}
}
<?php

    /**
     * gcj02转bd09
     *
     * @param double $lon
     * @param double $lat
     * @return array
     */
    public function gcj02_To_Bd09($lon, $lat)
    {
        load()->func('communication');
        $coords = $lon.','. $lat;
        $content = ihttp_get("http://api.map.baidu.com/geoconv/v1/?coords={$coords}&ak=9KtraRRDZT8xnAoVe3o41wGGgy4X3rMW");
        if (!empty($content['content'])) {
            $content = @json_decode($content['content'], true);

            if (isset($content['status']) && intval($content['status']) === 0 && !empty($content['result'])) {
                $data = current($content['result'] ?: []);

                return [
                    'longitude' => isset($data['x']) ? $data['x'] : 0,
                    'latitude' => isset($data['y']) ? $data['y'] : 0
                ];
            }
        }

        $x = doubleval($lon);
        $y = doubleval($lat);
        $z = sqrt($x * $x + $y * $y) + 0.00002 * sin($y * M_PI);
        $theta = atan2($y, $x) + 0.000003 * cos($x * M_PI);
        $lon = $z * cos($theta) + 0.0065;
        $lat = $z * sin($theta) + 0.006;

        return ['longitude' => $lon, 'latitude' => $lat];
    }
<?php

if (!function_exists('show_json')) {
	/**
	 * 输出json
	 *
	 * @param int $status 返回的status
	 * @param null $return 返回的result
	 * @param bool $exitBool 是否输出就结束
	 */
	function show_json($status = 1, $return = NULL, $exitBool = true)
	{
		global $_W;

		if (empty($_W['role'])){
			header('Content-type: application/json;');
		}
		$ret = array('status' => $status, 'result' => $status == 1 ? array('url' => referer()) : array());

		if (!is_array($return)) {
			if ($return) {
				$ret['result']['message'] = $return;
			}

			exit(json_encode($ret));
		}
		else {
			$ret['result'] = $return;
		}

		if (isset($return['url'])) {
			$ret['result']['url'] = $return['url'];
		}
		else {
			if ($status == 1) {
				$ret['result']['url'] = referer();
			}
		}

		echo json_encode($ret);

		if ($exitBool){
			exit();
		}else{
			ignore_user_abort();
			fastcgi_finish_request();
			set_time_limit(0);
		}
	}
}