52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
trait SendController
|
|
{
|
|
|
|
/**
|
|
* 数据返回
|
|
* @param int $code
|
|
* @param string $message
|
|
* @param array $data
|
|
* @param bool $withHttp
|
|
* @return string
|
|
*/
|
|
public static function returnMsg($code = 200, $message = '', $data = [], $withHttp = false)
|
|
{
|
|
|
|
$return['code'] = (int)$code;
|
|
$return['message'] = $message;
|
|
if(is_array($data)){
|
|
$return['data'] = $data;
|
|
}else{
|
|
$ob = (array)$data;
|
|
if(empty($ob)){
|
|
$return['data'] = (object)$data;
|
|
}else{
|
|
$return['data'] = $data;
|
|
}
|
|
}
|
|
if (true === $withHttp) {
|
|
return json($return)->code($code);
|
|
}
|
|
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
/** 调用APP登录 **/
|
|
public static function echoLogin()
|
|
{
|
|
echo '<script>
|
|
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
|
|
window.webkit.messageHandlers.LoginAction.postMessage(null);
|
|
} else if (/(Android)/i.test(navigator.userAgent)) {
|
|
jsObject.LoginAction();
|
|
}
|
|
</script>';
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|