auto update

dependabot/npm_and_yarn/ushio/www/session/lodash-4.17.15
iotcat 5 years ago
parent 81f06c1172
commit 97af3d9fa0
  1. 1
      ushio/www/api/.gitignore
  2. 255
      ushio/www/api/functions.php
  3. 59
      ushio/www/api/gugu/index.php
  4. 50
      ushio/www/api/gugu/intro.html
  5. 14
      ushio/www/api/mail/index.php
  6. 44
      ushio/www/api/mail/intro.html
  7. 31
      yimian/www/smartfarm/html/index.html

@ -0,0 +1 @@
config.php

@ -1,6 +1,6 @@
<?php
include '/home/ushio/conf/dbKeys/log.db.key.php';
include '/home/ushio/www/api/config.php';
/**database connection**/
//connect to database
@ -217,7 +217,39 @@ function get_from_domain(){
}
/*****curl*****/
function curl__post($url = '', $param) {
if(empty($url)) {
return false;
}
$o = "";
foreach ($param as $k => $v) {
$o .= "$k=".urlencode($v)."&" ;
}
$postUrl = $url;
$curlPost = substr($o,0,-1);
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
/* get IP */
function get_ip(){
return getIp();
}
function getIp()
{
if (isset($_SERVER)) {
@ -269,3 +301,224 @@ function getImgsInfo($type){
return $arr;
}
/*****gugu*****/
function yimian__gugu($body){
$body = iconv("UTF-8","gbk//TRANSLIT",$body);
$url = "http://open.memobird.cn/home/printpaper";
return curl__post($url, array("ak" => $GLOBALS['ggj_ak'], "userID" => $GLOBALS['ggj_userID'], "memobirdID" => $GLOBALS['ggj_memobirdID'], "printcontent" => "T:".base64_encode($body)."", "timestamp" => "".time().""));
}
function gugu__send($ak, $userID, $memobirdID, $body){
$body = iconv("UTF-8","gbk//TRANSLIT",$body);
$url = "http://open.memobird.cn/home/printpaper";
return curl__post($url, array("ak" => $ak, "userID" => $userID, "memobirdID" => $memobirdID, "printcontent" => "T:".base64_encode($body)."", "timestamp" => "".time().""));
}
/** function for mail **/
function yimian__mail($to, $subject, $body, $from){
if($from == "") $from = "IoTcat 呓喵酱";
if($body == "") $body = "额(⊙﹏⊙) 未找到指定的邮件内容耶( •̀ ω •́ )y<br/><br/>更多信息请咨询<a href = 'https://iotcat.me'>IoTcat</a>期待你的回应啦~";
if($subject == "") $subject = "来自IoTcat的一声问候~";
$data = array(
'fromName' => $from, // 发件人名称
'from' => "admin@iotcat.xyz", // 发件地址
'to' => $to, // 收件地址
'replyTo' => "i@iotcat.me", // 回信地址
'subject' => $subject,
'html' => $body
);
// 当前请求区域
// 杭州
// API地址
$data['api'] = 'https://dm.aliyuncs.com/';
// API版本号
$data['version'] = '2015-11-23';
// 机房信息
$data['region'] = 'cn-hangzhou';
// AccessKeyId
$data['accessid'] = $GLOBALS['aym_AccessKey'];
// AccessKeySecret
$data['accesssecret'] = $GLOBALS['aym_SecretKey'];
// 是否成功
return aliyun($data);
}
//mail alliyun api
function aliyun($param)
{
// 重新组合为阿里云所使用的参数
$data = array(
'Action' => 'SingleSendMail', // 操作接口名
'AccountName' => $param['from'], // 发件地址
'ReplyToAddress' => "true", // 回信地址
'AddressType' => 1, // 地址类型
'ToAddress' => $param['to'], // 收件地址
'FromAlias' => $param['fromName'], // 发件人名称
'Subject' => $param['subject'], // 邮件标题
'HtmlBody' => $param['html'], // 邮件内容
'Format' => 'JSON', // 返回JSON
'Version' => $param['version'], // API版本号
'AccessKeyId' => $param['accessid'], // Access Key ID
'SignatureMethod' => 'HMAC-SHA1', // 签名方式
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), // 请求时间
'SignatureVersion' => '1.0', // 签名算法版本
'SignatureNonce' => md5(time()), // 唯一随机数
'RegionId' => $param['region'] // 机房信息
);
// 请求签名
$data['Signature'] = sign($data, $param['accesssecret']);
// 初始化Curl
$ch = curl_init();
// 设置为POST请求
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
// 请求地址
curl_setopt($ch, CURLOPT_URL, $param['api']);
// 返回数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// 提交参数
curl_setopt($ch, CURLOPT_POSTFIELDS, getPostHttpBody($data));
// 关闭ssl验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// 执行请求
$result = curl_exec($ch);
// 获取错误代码
$errno = curl_errno($ch);
// 获取错误信息
$error = curl_error($ch);
// 获取返回状态码
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// 关闭请求
curl_close($ch);
// 成功标识
$flag = TRUE;
// 如果开启了Debug
if (1) {
// 记录时间
$log = '[Aliyun] ' . date('Y-m-d H:i:s') . ': ' . PHP_EOL;
// 如果失败
if ( $errno ) {
// 设置失败
$flag = FALSE;
$log .= '邮件发送失败, 错误代码:' . $errno . ',错误提示: ' . $error . PHP_EOL;
}
// 如果失败
if ( 400 <= $httpCode ) {
// 设置失败
$flag = FALSE;
// 尝试转换json
if ( $json = json_decode($result) ) {
$log .= '邮件发送失败,错误代码:' . $json->Code . ',错误提示:' . $json->Message . PHP_EOL;
} else {
$log .= '邮件发送失败, 请求返回HTTP Code:' . $httpCode . PHP_EOL;
}
}
// 记录返回值
$log .= '邮件发送返回数据:' . serialize($result) . PHP_EOL;
// 写入文件
}
yimian__log("log_mail",array("timestamp" => date('Y-m-d H:i:s', time()), "to_" => $param['to'], "from_" => $param['fromName'], "subject" => $param['subject'], "body" => $param['html'], "success" => (($flag)?1:0), "return_" => $log));
// 返回结果
//echo $log;
return $flag;
}
/**
* 阿里云签名
*
* @static
* @access private
*
* @param array $param 签名参数
* @param string $accesssecret 秘钥
*
* @return string
*/
function sign($param, $accesssecret)
{
// 参数排序
ksort($param);
// 组合基础
$stringToSign = 'POST&' . percentEncode('/') . '&';
// 临时变量
$tmp = '';
// 循环参数列表
foreach ( $param as $k => $v ) {
// 组合参数
$tmp .= '&' . percentEncode($k) . '=' . percentEncode($v);
}
// 去除最后一个&
$tmp = trim($tmp, '&');
// 组合签名参数
$stringToSign = $stringToSign . percentEncode($tmp);
// 数据签名
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $accesssecret . '&', TRUE));
// 返回签名
return $signature;
}
/**
* 阿里云签名编码转换
*
* @static
* @access private
*
* @param string $val 要转换的编码
*
* @return string|string[]|null
*/
function percentEncode($val)
{
// URL编码
$res = urlencode($val);
// 加号转换为%20
$res = preg_replace('/\+/', '%20', $res);
// 星号转换为%2A
$res = preg_replace('/\*/', '%2A', $res);
// %7E转换为~
$res = preg_replace('/%7E/', '~', $res);
return $res;
}
/**
* 阿里云请求参数组合
*
* @static
* @access private
*
* @param array $param 发送参数
*
* @return bool|string
*/
function getPostHttpBody($param)
{
// 空字符串
$str = "";
// 循环参数
foreach ( $param as $k => $v ) {
// 组合参数
$str .= $k . '=' . urlencode($v) . '&';
}
// 去除第一个&
return substr($str, 0, -1);
}

@ -0,0 +1,59 @@
<?php
include '../functions.php';
header('Access-Control-Allow-Origin:*');
$error = "";
if(!isset($_REQUEST['ak'])) $error .= "ak, ";
if(!isset($_REQUEST['userID'])) $error .= "userID, ";
if(!isset($_REQUEST['memobirdID'])) $error .= "memobirdID, ";
if(!isset($_REQUEST['body'])) $error .= "body, ";
if($error != ""){
$error = substr($error, 0, -2);
$error .= "参数未填写!!";
echo json_encode(array("showapi_res_code" => 0, "showapi_res_error" => $error));
die();
}
$body = $_REQUEST['body'];
$ak = strtolower($_REQUEST['ak']);
$userID = $_REQUEST['userID'];
$memobirdID = strtolower($_REQUEST['memobirdID']);
$res = gugu__send($ak, $userID, $memobirdID, $body);
if(strpos($res,'showapi_res_code') === false){
$error = "";
if(strlen($ak) != 32 || !ctype_alnum($ak)) $error .= "ak, ";
if(strlen($userID) != 6 || !is_numeric($userID)) $error .= "咕咕号, ";
if(strlen($memobirdID) != 16 || !ctype_alnum($memobirdID)) $error .= "咕咕机编号, ";
if($error != ""){
$error = substr($error,0,-2);
$error .= "格式错误!!";
}else{
$error .= "ak, 咕咕号或咕咕机编号错误!";
}
echo json_encode(array("showapi_res_code" => 0, "showapi_res_error" => $error));
}else{
echo $res;
}
yimian__log("log_gugu", array("timestamp" => date('Y-m-d H:i:s', time()), "ip" => ip2long(get_ip()), "body" => $body, "who" => md5($userID) /* 经md5不可逆加密,仅用于区分用户 */));
yimian__log("log_api", array("api" => "gugu", "timestamp" => date('Y-m-d H:i:s', time()), "ip" => ip2long(get_ip()), "_from" => get_from(), "content" => md5($userID).": ".md5($body)/* 经md5加密,仅用于区分不同内容*/));
die();

@ -0,0 +1,50 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>咕咕机 API</title>
<meta name="theme-color" content="#fd4b5c">
<script src="https://cdn.yimian.xyz/ushio-js/ushio-head.min.js"></script>
</head>
<body>
<style type="text/css">h3:hover {box-shadow:0px 0px 8px #D1D1D1;}</style>
<div style="box-shadow: 5px 5px 25px 0 rgba(46,61,73,.2);border-radius:15px;font-size:13px;width:950px;font-family:微软雅黑,'Helvetica Neue',Arial,sans-serif;margin:10px auto 0px;border:0px solid #eee;max-width:100%;">
<div style="width:100%;background-color: #3174ed;background-image: linear-gradient(90deg, #3174ed 0%, #FA8BFF 35%, #3fd9fb 88%);color:#FFFFFF;border-radius:15px 15px 0 0;">
<h2 style="font-size:15px;word-break:break-all;padding:20px 32px;margin:0;text-align:center">咕咕机 - API</h2></div>
<div style="margin:0px auto;width:90%">
<h3 style="-webkit-transition: all .2s cubic-bezier(0, 0, 0, 0.48);-moz-transition: all .2s ease;border:.0625rem solid #fafafa;background:#fafafa repeating-linear-gradient(-45deg,#fff,#fff 1.125rem,transparent 1.125rem,transparent 2.25rem);margin:15px 0px;padding:20px;border-radius:5px;font-size:14px;color:#333;">
# 咕咕机发送API请求方式 #
<ul>
<li>Method: GET/POST</li>
</ul>
<hr>
# 请求地址 #<br/>
<a style="color:#fd4b5c;text-decoration:none;">https://api.yimian.xyz/gugu</a><br/>
# 参数 #<br/>
<li>ak //咕咕机AccessKey(前往<a href="http://open.memobird.cn">咕咕机开放平台</a>申请)</li>
<li>userID //用户的咕咕号(手机软件>>我的>>头像旁边的咕咕号)</li>
<li>memobirdID //咕咕机ID(手机软件>>我的>>我的咕咕机>>咕咕机>>设备编号)</li>
<li>body //内容</li>
<hr>
# 返回数据(Json格式) #<br/>
<li>showapi_res_code //1为发送成功,0为失败</li>
<li>showapi_res_error //"ok"为发送成功,否则显示错误信息</li>
<li>result //1为打印成功</li>
<li>smartGuid //会话标识符</li>
<li>printcontentid //打印内容识别编码</li>
<li>更多用法见<a href="http://open.memobird.cn/upload/webapi.pdf">官方文件</a></li>
<hr>
# 备注 #<br/>
次API仅为官方接口的二次封装,意在降低其使用门槛。本站承诺不会保存任何使用者信息。如果您对本站存有疑惑,请慎重使用本接口!!<a href="https://github.com/IoTcat/IoTgod-Fabric/blob/master/server/cn/home/www/api/www-api/gugu/index.php">本接口源码</a><br/>
<hr>
# 示例 (类似这个格式)#<br/>
<a style="color:#fd4b5c;text-decoration:none;" target="_blank">https://api.yimian.xyz/gugu?ak=9e55121803474371bfa25d20e554b31d&userID=832598&memobirdID=c3ee06a8bd9b49e1&body=你好呀世界</a>
</h3>
</div>
</div>
</body>
<script src="https://cdn.yimian.xyz/ushio-js/ushio-footer.min.js"></script>
</html>

@ -0,0 +1,14 @@
<?php
include '../functions.php';
header('Access-Control-Allow-Origin:*');
if(!isset($_REQUEST['body'])) $_REQUEST['body'] = "";
if(!isset($_REQUEST['from'])) $_REQUEST['from'] = "";
echo json_encode(array("state" => yimian__mail($_REQUEST['to'], $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['from'])));
yimian__log("log_api", array("api" => "mail", "timestamp" => date('Y-m-d H:i:s', time()), "ip" => ip2long(get_ip()), "_from" => get_from(), "content" => $_REQUEST['to']."|".$_REQUEST['subject']."|".$_REQUEST['body']."|".$_REQUEST['from']));
die();

@ -0,0 +1,44 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>邮件 API</title>
<meta name="theme-color" content="#fd4b5c">
<script src="https://cdn.yimian.xyz/ushio-js/ushio-head.min.js"></script>
</head>
<body>
<style type="text/css">h3:hover {box-shadow:0px 0px 8px #D1D1D1;}</style>
<div style="box-shadow: 5px 5px 25px 0 rgba(46,61,73,.2);border-radius:15px;font-size:13px;width:950px;font-family:微软雅黑,'Helvetica Neue',Arial,sans-serif;margin:10px auto 0px;border:0px solid #eee;max-width:100%;">
<div style="width:100%;background-color: #3174ed;background-image: linear-gradient(90deg, #3174ed 0%, #FA8BFF 35%, #3fd9fb 88%);color:#FFFFFF;border-radius:15px 15px 0 0;">
<h2 style="font-size:15px;word-break:break-all;padding:20px 32px;margin:0;text-align:center">邮件 - API</h2></div>
<div style="margin:0px auto;width:90%">
<h3 style="-webkit-transition: all .2s cubic-bezier(0, 0, 0, 0.48);-moz-transition: all .2s ease;border:.0625rem solid #fafafa;background:#fafafa repeating-linear-gradient(-45deg,#fff,#fff 1.125rem,transparent 1.125rem,transparent 2.25rem);margin:15px 0px;padding:20px;border-radius:5px;font-size:14px;color:#333;"># 邮件API请求方式 #
<ul>
<li>Method: GET/POST</li></ul>
<hr># 请求地址 #
<br/>
<a style="color:#fd4b5c;text-decoration:none;">https://api.yimian.xyz/mail</a>
<br/># 参数 #
<br/>
<li>to //to=i@iotcat.me 收件地址</li>
<li>subject //subject=邮件主题 utf-8编码</li>
<li>body //body=邮件主体 utf-8编码</li>
<li>from //from=呓喵酱 发件人名称</li>
<hr>
# 返回数据(JSON) #<br/>
<li>state: true/false 成功/失败</li>
<hr># 备注 #
<br/>更多用法参考
<a href="https://www.eee.dog/tech/rand-pic-api.html">https://www.eee.dog/tech/rand-pic-api.html</a>
<br/>
<hr># 示例 #
<br/>
<a style="color:#fd4b5c;text-decoration:none;" target="_blank">https://api.yimian.xyz/mail/?to=i@iotcat.me&subject=hello&body=hello%20mail&from=路人A</a></h3>
</div>
</div>
</body>
<script src="https://cdn.yimian.xyz/ushio-js/ushio-footer.min.js"></script>
</html>

@ -43,6 +43,20 @@
</div>
<script>
/* global var */
var page = {
msg: "This is a temporary page! "+
"4 Fake Nodes are working!! "+
"If you want to shutdown the Fake Nodes, Please let me know!! "+
"Next official Page will be pushed out in next week! "+
"Status Code 0 represents ok and open!! "+
"Status Code 1 represents close!! ",
charNum: 40,
interval: 4000,
title: document.title,
};
/* request */
$('.refresh').attr('onClick', '$.get("https://smartfarm.yimian.xyz/api/refresh");');
setInterval(function(){
@ -157,6 +171,23 @@ setInterval(function(){
}
});
}, 2000);
/* title anime */
function anime_title(){
for(var i = 0; i < page.msg.length; i ++){
setTimeout((i)=>{
document.title = page.msg.substr(i, page.charNum);
if(i == page.msg.length - 1){
setTimeout(()=>{
document.title = page.title;
setTimeout(anime_title, page.interval);
}, 300);
}
}, i * 300, i);
}
}
setTimeout(anime_title, 4000);
</script>
</html>
Loading…
Cancel
Save