Commit 866e88e9 authored by wanjilong's avatar wanjilong
parents d0e1aa8a 15534ea4
...@@ -5,22 +5,28 @@ namespace Api\PhpUtils\Common; ...@@ -5,22 +5,28 @@ namespace Api\PhpUtils\Common;
class GoodsSkuId class GoodsSkuId
{ {
const TABLE_TAG_GENERAL = "000";//普通表 goods_sku 商品
const TABLE_TAG_PINDAN = "001";//接龙表 pindan_goods_sku 商品
/** /**
* 生成加密后的 sku_id * 生成加密后的 sku_id
* id 非雪花算法生成的sku_id * id 非雪花算法生成的sku_id
* category_1_id 一级分类的id,两位,不足两位在十位补零 * category_1_id 一级分类的id,两位,不足两位在十位补零
* category_2_id 二级分类的id,两位,不足三位在百位补零 * category_2_id 二级分类的id,两位,不足三位在百位补零
* spu 商品类型,1虚拟商品,2实体商品 * goodsType 商品类型,1虚拟商品,2实体商品 占一位
* goodsType 1、(默认)第三方商品 2、自营商品 * belongType 1、(默认)第三方商品 2、自营商品 占一位
* tableTag 数据所在表: 000: goods_sku, 001: pindan_goods_sku
* *
* @param $id * @param $id
* @param $category1Id * @param $category1Id
* @param $category2Id * @param $category2Id
* @param $spuType * @param $spuType
* @param $goodsType * @param $goodsType
* @param $belongType
* @param $tableTag
* @return string * @return string
*/ */
public static function generateGoodSkuId($id, $category1Id, $category2Id, $spuType, $goodsType = 1) public static function generateGoodSkuId($id, $category1Id, $category2Id, $goodsType, $belongType = 1, $tableTag = "000")
{ {
if (strlen($category1Id) == 1) { if (strlen($category1Id) == 1) {
$category1Id = "0" . $category1Id; $category1Id = "0" . $category1Id;
...@@ -28,7 +34,7 @@ class GoodsSkuId ...@@ -28,7 +34,7 @@ class GoodsSkuId
if (strlen($category2Id) == 2) { if (strlen($category2Id) == 2) {
$category2Id = "0" . $category2Id; $category2Id = "0" . $category2Id;
} }
$idStr = $id . $category1Id . $category2Id . $spuType . $goodsType; $idStr = $id . $category1Id . $category2Id . $goodsType . $belongType . $tableTag;
//转62进制 //转62进制
$tmp = BaseConvert::decToOther($idStr); $tmp = BaseConvert::decToOther($idStr);
...@@ -97,4 +103,79 @@ class GoodsSkuId ...@@ -97,4 +103,79 @@ class GoodsSkuId
return $ret === $code; return $ret === $code;
} }
/**
* 恢复加密前的订单号
* @param $str
* @return bool|int|string
*/
public static function recoverGoodSkuId($str)
{
$strlen = strlen($str);
$chklen = 2;
$code = substr($str, -$chklen);
$str = substr($str, 0, $strlen-$chklen);
$strlen -= $chklen;
$base = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ($strlen % 2 == 1)
{
$str = '0' . $str;
$strlen += 1;
}
$sum = 0;
$len = $strlen/2;
for ($i=0; $i<$len; $i++)
{
$sum *= 137;
$sum += ord($str[$i]) ^ ord($str[$strlen-$i-1]);
}
$ret = '';
for ($i=$chklen; $i>0; $i--)
{
$idx = $sum % 62;
$sum = ($sum-$idx) / 62;
$ret = $base[$idx] . $ret;
}
if ($ret === $code) {
$codeLen = strlen($code);
return BaseConvert::otherToDec($str);
}
return "";
}
/**
* 根据skuId获取对应的参数
* @param $goodsSkuId
* @return array
*/
public static function getGoodsSkuIdParams($goodsSkuId)
{
$goodsSkuIdNum = self::recoverGoodSkuId($goodsSkuId);
$data = [];
if (!empty($goodsSkuIdNum)) {
$idgenId = substr($goodsSkuIdNum, 0, 20);
$category1Id = substr($goodsSkuIdNum, 20, 2);
$category2Id = substr($goodsSkuIdNum, 22, 3);
$goodsType = substr($goodsSkuIdNum, 25, 1);
$belongType = substr($goodsSkuIdNum, 26, 1);
$tableTag = substr($goodsSkuIdNum, 27, 3);
$data = [
"idgent_id" => $idgenId,
"category_1_id" => $category1Id,
"category_2_id" => $category2Id,
"goods_type" => $goodsType,
"belong_type" => $belongType,
"table_tag" => $tableTag,
];
}
return $data;
}
} }
\ No newline at end of file
...@@ -62,21 +62,10 @@ class FileLog ...@@ -62,21 +62,10 @@ class FileLog
$exception_info = ''; $exception_info = '';
} }
$log .= ' [exception info: ]' . $exception_info; $log .= ' [exception info: ]' . $exception_info;
$log .= ' [debug_backtrace info: ]' . print_r(debug_backtrace(), 1);
error_log($log); error_log($log);
if (empty($mail_to)) { if (empty($mail_to)) {
$mail_to = [ $mail_to = 'bp-server@yidian-inc.com';
'wangdanfeng@yidian-inc.com',
'cuiweifeng@yidian-inc.com',
'luhongguang@yidian-inc.com',
'wangdong1@yidian-inc.com',
'wanjilong@yidian-inc.com',
'jianghaiming@yidian-inc.com',
'songxiaohang@yidian-inc.com',
'genghongfei@yidian-inc.com',
'mengweifu@yidian-inc.com',
'guozhiyuan@yidian-inc.com',
'suntengda@yidian-inc.com'
];
} }
$subject = 'App api #' . $signature . '# ' . $_SERVER['SERVER_NAME'] . ' (' . $_SERVER['SERVER_ADDR'] . ') Alert Message'; $subject = 'App api #' . $signature . '# ' . $_SERVER['SERVER_NAME'] . ' (' . $_SERVER['SERVER_ADDR'] . ') Alert Message';
$body = 'Error: ' . $signature . "\n\n"; $body = 'Error: ' . $signature . "\n\n";
...@@ -94,7 +83,7 @@ class FileLog ...@@ -94,7 +83,7 @@ class FileLog
} }
} }
private static function accessLog() public static function accessLog()
{ {
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
$query = http_build_query($_GET, '', '&'); $query = http_build_query($_GET, '', '&');
...@@ -120,7 +109,7 @@ class FileLog ...@@ -120,7 +109,7 @@ class FileLog
fclose($log_file); fclose($log_file);
} }
private static function ip() public static function ip()
{ {
if (isset($_SERVER['IPV6_REMOTE_ADDR']) && !empty($_SERVER['IPV6_REMOTE_ADDR']) && trim($_SERVER['IPV6_REMOTE_ADDR']) !== '-') { // 如果没有ipv6地址, 运维会传一个占位符“-” if (isset($_SERVER['IPV6_REMOTE_ADDR']) && !empty($_SERVER['IPV6_REMOTE_ADDR']) && trim($_SERVER['IPV6_REMOTE_ADDR']) !== '-') { // 如果没有ipv6地址, 运维会传一个占位符“-”
$ips = $_SERVER['IPV6_REMOTE_ADDR']; $ips = $_SERVER['IPV6_REMOTE_ADDR'];
...@@ -137,7 +126,7 @@ class FileLog ...@@ -137,7 +126,7 @@ class FileLog
return $ip[0]; return $ip[0];
} }
private static function shouldSendEmail($key) public static function shouldSendEmail($key)
{ {
$result = true; $result = true;
// 每分钟发一条 // 每分钟发一条
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Api\PhpUtils\Message; namespace Api\PhpUtils\Message;
use Yaf\Application;
class Email class Email
{ {
/** /**
...@@ -19,6 +21,10 @@ class Email ...@@ -19,6 +21,10 @@ class Email
if (empty($to)) { if (empty($to)) {
return false; return false;
} }
$env = Application::app()->environ();
if($env != 'test' && $env != 'prod' && $env != 'perf'){
return false;
}
if (empty($from)) { if (empty($from)) {
$from = 'noreply@yidian-inc.com'; $from = 'noreply@yidian-inc.com';
} }
...@@ -30,6 +36,16 @@ class Email ...@@ -30,6 +36,16 @@ class Email
fwrite($sock, "HELO " . $domain . "\r\n"); fwrite($sock, "HELO " . $domain . "\r\n");
fgets($sock); fgets($sock);
fwrite($sock, "auth login\r\n");
fgets($sock);
fwrite($sock, "YnAtbm9yZXBseQ==\r\n");
fgets($sock);
fwrite($sock, "VlhObGNtNWhiJFclVTY=\r\n");
fgets($sock);
fwrite($sock, "MAIL FROM:<" . $from . ">\r\n"); fwrite($sock, "MAIL FROM:<" . $from . ">\r\n");
fgets($sock); fgets($sock);
if (!is_array($to)) { if (!is_array($to)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment