Authored by hf

code review by fei.hong : do format yuchouqian huodong

... ... @@ -42,6 +42,13 @@ class HuodongAction extends Controller_Abstract
protected $_data;
/**
* 是否是APP访问
*
* @var bool
*/
protected $_isApp;
/**
* 初始化
*/
public function init()
... ... @@ -58,6 +65,8 @@ class HuodongAction extends Controller_Abstract
if (isset($config->css->url)) {
$this->_view->assign('imgUrl', $config->img->url);
}
$this->_isApp = (null !== $this->get('app_version') || null !== $this->get('uid'));
}
/**
... ...
... ... @@ -20,6 +20,9 @@ class ActivityData
const URI_GET_NAMED_COUPON = 'event/api/v1/activity/getCoupon';
const URI_GET_ALL_COUPON = 'event/api/v1/activity/getCoupon';
const URI_SEND_MESSAGE = 'inbox/service/v1/inbox';
const URI_YUANXIAO_CHOUQIAN = 'union/ActivityRest/draw';
const URI_YUANXIAO_CHOUQIAN_SHARE = 'union/ActivityRest/getDrawInfo';
const URL_YUANXIAO_API = 'http://union.yoho.cn/';
/**
* 用户获取某个活动指定的单个优惠券
... ... @@ -69,9 +72,51 @@ class ActivityData
}
/**
* 获取元宵抽签的结果
*
* @param int $uid 用户UID
* @param string $nickName 用户昵称
* @param string $birthday 用户生日
* @param int $gender 用户性别
* @return mixed 抽签的结果
*/
public static function getYuanxiaoInfo($uid, $nickName, $birthday, $gender)
{
$param = array();
$param['method'] = 'wap.activity.draw';
$param['uid'] = $uid;
$param['nickname'] = $nickName;
$param['birthday'] = $birthday;
$param['gender'] = $gender;
return Yohobuy::jsonPost(self::URL_YUANXIAO_API . self::URI_YUANXIAO_CHOUQIAN, $param);
}
/**
* 获取分享结果页元宵抽签的结果
*
* @param int $uid 用户UID
* @return mixed 抽签的结果
*/
public static function getYuanxiaoShareInfo($uid)
{
$param = array();
$param['method'] = 'wap.activity.draw';
$param['uid'] = $uid;
return Yohobuy::jsonPost(self::URL_YUANXIAO_API . self::URI_YUANXIAO_CHOUQIAN_SHARE, $param);
}
/**
* 发送站内信
*
* @param int $activityId 活动ID
* @param int $uid
* @param string $title
* @param int $content
* @param int $type
* @param string $verify_key
* @param int $send_uid
* @param string $call_back
* @return array
*/
public static function message($uid, $title, $content, $type = 1, $verify_key = '', $send_uid = 0, $call_back = '')
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>{{staticTitle}}</title>
<!-- <meta name="apple-mobile-web-app-title" content="SUMMER SALE"> -->
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="grey">
<script>
(function(d,c){var e=d.documentElement,a="orientationchange" in window?"orientationchange":"resize",b=function(){var f=e.clientWidth;if(!f){return}if(f>=640){e.style.fontSize="80px"}else{e.style.fontSize=80*(f/640)+"px"}};if(!d.addEventListener){return}b();c.addEventListener(a,b,false);d.addEventListener("DOMContentLoaded",b,false)})(document,window);
</script>
</head>
<body>
<div class="main-wrap">
元宵节抽签
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap home">
<div class="header"></div>
<div class="people">
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
</div>
</body>
<a class="start" href="{{playUrl}}"></a>
<div class="footer">
<a class="arrow animated infinite pulse" href="{{playUrl}}"></a>
<div class="yohobuy"></div>
</div>
</div>
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap info">
<div class="header">
<span class="title chao">潮</span>
<span class="title liu">流</span>
<div class="sub-title">&nbsp;开运测试</div>
</div>
{{#if message}}
<div class="err-tip">
活动太火爆,请稍后再试
</div>
{{else}}
<form class="user" method="POST">
<div class="user-info nick">
<div class="title">
昵称
</div>
<input type="text" name="nick" placeholder="请输入您帅气的名字!" value="" maxlength="20">
</div>
<div class="user-info birthday">
<div class="title">
生日
</div>
<input class="birthday-picker" type="text" name="birthday" value="{{birthday}}" data-number="{{birthdayNumber}}" readonly>
</div>
<div class="gender">
<div class="title">
性<br>别
</div>
<div class="icon boy">
<span class="check {{#if isBoy}}checked{{/if}}" data-gender="1"></span>
</div>
<div class="icon girl">
<span class="check {{#unless isBoy}}checked{{/if}}" data-gender="2"></span>
</div>
<input type="hidden" name="gender" id="gender" value="{{gender}}">
</div>
</form>
<div class="footer">
<div class="submit">
开始测试
</div>
</div>
{{/if}}
<div class="mask hide">
<div class="modal">
<div class="icon close"></div>
<div class="text">
请输入您
<br>
帅气的名字!
</div>
<div class="btn close">
现在就完善
</div>
</div>
</div>
</div>
<link rel="stylesheet" type="text/css" href="http://cdn.yoho.cn/huodong/2016yuanxiao/AnyPicker/dist/anypicker-all.min.css" />
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap result">
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
<div class="title">
<p>
{{result.name}}
</p>
2016年的潮流运势是
</div>
<div class="hr">
</div>
<div class="type {{result.type}}" data-type="{{result.type}}">
</div>
<div class="footer">
{{#if needShare}}
<div class="share">
分享2016年潮流运势
</div>
{{/if}}
</div>
<div class="mask hide">
<div class="share-icon">
</div>
</div>
</div>
{{> cuxiao/yuanxiao/type}}
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap share">
<div class="header"></div>
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
<div class="title">
<p>
{{result.name}}
</p>
2016年的潮流运势是
</div>
<div class="type {{result.type}}" data-type="{{result.type}}">
</div>
<div class="count">
已有{{count}}人参与
</div>
<div class="footer">
<a class="entry" href="/cuxiao/yuanxiao/index">
我也要测
</a>
</div>
</div>
{{> cuxiao/yuanxiao/type}}
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap wait">
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
<div class="tip">
正在分析你的<br>潮流运势<br>…
</div>
<div class="loading">
</div>
<div class="hat">
</div>
<div class="footer">
</div>
</div>
<script type="text/javascript">
setTimeout(function (){
location.href = '{{activityUrl}}';
// location.href = '{{activityUrl}}?openby:yohobuy={"action":"go.h5","params":{"title":"元宵抽签","url":"{{activityUrl}}","share":"\/operations\/api\/v5\/webshare\/getShare","shareparam":{"share_id":"1"},"param":{"share_id":"1"}}}';
}, 2000);
</script>
{{> cuxiao/yuanxiao/footer}}
... ...
<input type="hidden" id="shareTitle" value="{{shareTitle}}">
<input type="hidden" id="shareDesc" value="{{shareDesc}}">
<input type="hidden" id="shareImg" value="{{shareImg}}">
<input type="hidden" id="shareLink" value="{{shareUrl}}">
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
<script type="text/javascript" src="{{staticFile}}/js/libs.js"></script>
{{#staticJS}}
<script type="text/javascript" src="{{../staticFile}}/js/{{.}}"></script>
{{/staticJS}}
</body>
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>{{staticTitle}}</title>
<!-- <meta name="apple-mobile-web-app-title" content="SUMMER SALE"> -->
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="grey">
<script type="text/javascript">
(function(d,c){var e=d.documentElement,a="orientationchange" in window?"orientationchange":"resize",b=function(){var f=e.clientWidth;if(!f){return}if(f>=640){e.style.fontSize="40px"}else{e.style.fontSize=40*(f/640)+"px"}};if(!d.addEventListener){return}b();c.addEventListener(a,b,false);d.addEventListener("DOMContentLoaded",b,false)})(document,window);
</script>
<link rel="stylesheet" href="{{staticFile}}/css/style.css">
</head>
<body>
... ...
<script type="text/tmpl" id="P1">
<div class="bg-guang"></div>
<div class="bg-yuan"></div>
<div class="title">成为一个大写加粗的</div>
<div class="chaoren animated infinite pulse"></div>
</script>
<script type="text/tmpl" id="P2">
<div class="bg-bige animated zoomIn"></div>
<div class="bg-manzai animated zoomIn"></div>
<div class="bg-ren"></div>
<div class="title animated infinite pulse"></div>
<div class="yzbb animated slideInDown"></div>
</script>
<script type="text/tmpl" id="P3">
<div class="bg-yunqi animated zoomIn"></div>
<div class="shoes animated infinite swing"></div>
<div class="yeezy animated slideInDown"></div>
</script>
<script type="text/tmpl" id="P4">
<div class="bg-car"></div>
<div class="hands animated infinite swing"></div>
<div class="wanghong animated slideInRight"></div>
</script>
<script type="text/tmpl" id="M1">
<div class="bg-majia"></div>
<div class="bg-yifei animated slideInUp"></div>
<div class="flyman flyIn "></div>
</script>
<script type="text/tmpl" id="M2">
<div class="bg-bamei animated slideInRight"></div>
<div class="meizi animated infinite swing"></div>
<div class="shoes"></div>
</script>
<script type="text/tmpl" id="M3">
<div class="bg-cloud1 animated slideInRight"></div>
<div class="bg-chuanzhe animated slideInLeft"></div>
<div class="shan"></div>
<div class="rensheng"></div>
<div class="cloud2 animated slideInRight"></div>
<div class="shoes animated infinite swing"></div>
</script>
<script type="text/tmpl" id="M4">
<div class="bg-guang"></div>
<div class="bg-jin1 animated slideInright"></div>
<div class="ren"></div>
<div class="jin2 animated slideInDown"></div>
<div class="jin3 animated slideInDown"></div>
<div class="shuaiqi animated slideInDown"></div>
</script>
<script type="text/tmpl" id="F1">
<div class="bg-hezi1 animated slideInLeft"></div>
<div class="bg-hezi2 animated slideInDown"></div>
<div class="bg-hezi3 animated slideInRight"></div>
<div class="sun animated infinite zoomIn"></div>
<div class="kuaidi animated slideInDown"></div>
</script>
<script type="text/tmpl" id="F2">
<div class="bg-love1 animated infinite zoomIn"></div>
<div class="bg-love2"></div>
<div class="boy animated slideInRight"></div>
<div class="girl animated slideInLeft"></div>
<div class="bidong animated slideInRight"></div>
</script>
<script type="text/tmpl" id="F3">
<div class="bg-bra animated infinite pulse"></div>
<div class="xiongda animated zoomIn"></div>
</script>
<script type="text/tmpl" id="F4">
<div class="bg-guang animated infinite zoomIn"></div>
<div class="bg-shoes1 animated slideInLeft"></div>
<div class="bg-shoes2 animated slideInRight"></div>
<div class="bg-shoes3 animated slideInDown"></div>
<div class="style animated slideInUp"></div>
</script>
... ...
<?php
namespace Cuxiao;
use LibModels\Wap\Cuxiao\ActivityData;
use LibModels\Wap\Home\UserData;
/**
* Created by PhpStorm.
* User: Gtskk
* Date: 2016/2/18
* Time: 16:26
*
* @name YuanxiaoModel
* @package models/Cuxiao
* @author Gtskk(tttt6399998@126.com)
*/
class YuanxiaoModel
{
/**
* 处理用户详情数据
*
* @param int $uid 用户ID
* @return array|mixed 处理之后的个人详情数据
*/
public static function getUserProfileData($uid)
{
$result = array(
'birthday' => '2000-01-01',
'gender' => 2
);
// 调用接口获取个人详情
$userData = UserData::userData($uid, false);
// 处理个人详情数
if (isset($userData['data']) && !empty($userData['data'])) {
$result['birthday'] = $userData['data']['birthday'] ?: '2000-01-01';
$result['gender'] = $userData['data']['gender'];
}
return $result;
}
/**
* @param int $uid 用户UID
* @param sring $nickName 用户昵称
* @param string $birthday 用户生日
* @param int $gender 用户性别
* @return array 处理之后抽签的结果
*/
public static function getChouqianInfo($uid, $nickName, $birthday, $gender)
{
$result = array('code' => 400, 'message' => '出错啦~');
do {
if (empty($uid)) {
break;
}
if (empty($nickName)) {
$result['message'] = '昵称不能为空';
break;
}
if (empty($birthday)) {
$result['message'] = '生日不能为空';
break;
}
if (empty($gender)) {
$result['message'] = '性别不能为空';
break;
}
$chouqian = ActivityData::getYuanxiaoInfo($uid, $nickName, $birthday, $gender);
if ($chouqian) {
$result = $chouqian;
}
} while (false);
return $result;
}
/**
* @param int $uid 用户UID
* @return array|mixed 抽奖的结果
*/
public static function getChoujiangShareInfo($uid)
{
$result = array('code' => 400, 'message' => '出错啦~');
do {
if (empty($uid)) {
break;
}
$chouqian = ActivityData::getYuanxiaoShareInfo($uid);
if (isset($chouqian['data'])) {
$result = array(
'name' => $chouqian['data']['nickname'],
'type' => $chouqian['data']['randomCode'],
'total' => $chouqian['data']['total']
);
}
} while (false);
return $result;
}
}
\ No newline at end of file
... ...
<?php
use Action\HuodongAction;
use Cuxiao\YuanxiaoModel;
use Plugin\Helpers;
use LibModels\Wap\Cuxiao\ActivityData;
use Api\Yohobuy;
/**
* 元宵抽签活动
*/
class YuanxiaoController extends HuodongAction
{
// const STATIC_FILE = 'http://localhost:2222/assets/1.1.3';
const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.1.3';
const ENCRYPT_KEY = 'iamgtskkwhoareyou';
/**
* 通过当前用户审判是否跳到登录页
*
*/
private function auditJumpLogin()
{
$uid = $this->getLoggedUid();
if (!$uid || !is_numeric($uid)) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
}
}
/**
* 元宵抽签
*/
public function indexAction()
{
$playUrl = Helpers::url('/cuxiao/yuanxiao/info');
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$this->_view->display('index', array(
'staticTitle' => '元宵抽签'
'staticTitle' => '2016潮流运势测试!',
'staticFile' => self::STATIC_FILE,
'staticJS' => array(
'home.js'
),
'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
'playUrl' => $this->isApp() ? $playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}': $playUrl,
));
}
/**
* 元宵抽签 信息
*/
public function infoAction()
{
$uid = $this->getLoggedUid();
if (!$uid) {
if (!$this->_isApp) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
} else {
exit();
}
}
// POST提交请求
$posts = $this->post();
if (!empty($posts)) {
$nickName = $this->post('nick', '');
$birthday = $this->post('birthday', '');
$gender = $this->post('gender', 1);
// 格式化日期以便接口接收
$FormatBirthday = date_format(date_create_from_format('Y年m月d日', $birthday), 'Y-m-d');
// 调用接口
$result = YuanxiaoModel::getChouqianInfo($uid, $nickName, $FormatBirthday, $gender);
if ($result['code'] === 200) { // 处理成功就跳转到等待页
// 将返回的结果存入cookeie中15分钟
$cookieData = array(
'name' => $nickName,
'type' => $result['data']['randomCode']
);
$this->setCookie('yuanxiaochouqian', json_encode($cookieData), time() + 15 * 60);
$this->go(Helpers::url('/cuxiao/yuanxiao/wait'));
} else { // 不成功就显示返回的错误信息
$this->_view->display('info', array(
'staticTitle' => '2016潮流运势测试!',
'staticFile' => self::STATIC_FILE,
'staticJS' => array(
'info.js'
),
'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
'birthday' => $birthday,
'birthdayNumber' => $FormatBirthday,
'gender' => $gender,
'isBoy' => $gender == 1, // 性别是否是女标志位
'message' => $result['message']
));
}
} else {
$userData = YuanxiaoModel::getUserProfileData($uid);
// 接口返回空数据时,设置默认值
if (empty($userData['birthday']) || $userData['birthday'] === '0000-00-00') {
$userData = array(
'birthday' => '1990-01-01',
'gender' => '3',
);
}
$this->_view->display('info', array(
'staticTitle' => '2016潮流运势测试!',
'staticFile' => self::STATIC_FILE,
'staticJS' => array(
'info.js'
),
'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
'birthday' => date_format(date_create($userData['birthday']), 'Y年m月d日'),
'birthdayNumber' => $userData['birthday'],
'gender' => $userData['gender'],
'isBoy' => $userData['gender'] == 1 // 性别是否是女标志位
));
}
}
/**
* 元宵抽签 等待
*/
public function waitAction()
{
// 审判跳转登录页
// $this->auditJumpLogin();
$this->_view->display('wait', array(
'staticTitle' => '2016潮流运势测试!',
'staticFile' => self::STATIC_FILE,
'activityUrl' => Helpers::url('/cuxiao/yuanxiao/result'),
'staticJS' => array(
'wait.js'
),
'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
));
}
/**
* 元宵抽签 结果
*/
public function resultAction()
{
// 审判跳转登录页
//$this->auditJumpLogin();
$result = $this->getCookie('yuanxiaochouqian', null);
if (empty($result)) { // 未取到信息就重新测试
$this->go(Helpers::url('/cuxiao/yuanxiao/info'));
}
// cookie中存的结果
$result = json_decode($result, true);
$shareUrl = Helpers::url('/cuxiao/yuanxiao/share', array(
'hash' => $this->encrypt($this->getUid()),
'type' => $this->encrypt($result['type'])
));
$this->_view->display('result', array(
'staticTitle' => '2016潮流运势测试!',
'needShare' => $this->checkNeedShare(), // 是否需要微信分享
'staticFile' => self::STATIC_FILE,
'result' => $result,
'shareTitle' => $result['name'] . '的2016年潮流运势是' . $this->getChouqianTitle($result['type']),
'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareUrl' => $shareUrl,
'staticJS' => array(
'result.js'
)
));
}
/**
* 元宵抽签 分享
*/
public function shareAction()
{
// 用户UID
$uid = $this->decrypt($this->get('hash', ''));
if (empty($uid)) {
$this->go(Helpers::url('/cuxiao/yuanxiao/index'));
}
// 抽签结果
$type = $this->decrypt($this->get('type', ''));
// 调用接口获取type和count
$result = YuanxiaoModel::getChoujiangShareInfo($uid);
$this->_view->display('share', array(
'staticTitle' => '2016潮流运势测试!',
'staticFile' => self::STATIC_FILE,
'result' => array(
'name' => $result['name'],
'type' => $type ?: $result['type']
),
'count' => $result['total'],
'staticJS' => array(
'share.js'
),
'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png'
));
}
/**
* 根据结果类型获取抽签结果标题
* @param $type
*/
private function getChouqianTitle($type)
{
$data = array(
'P1' => '成为一个大写加粗的潮人!',
'P2' => '逼格满载盐值爆表!',
'P3' => '运气爆棚,拥有Yeezy不是梦!',
'P4' => '街拍不断,成为网红不是梦!',
'M1' => '穿着MA-1飞行夹克一飞冲天!',
'M2' => '把妹不花钱!买鞋不排队!',
'M3' => '穿着跑鞋到达人生巅峰!',
'M4' => '帅气多金颜值高!',
'F1' => '拥有拆不完的快递和礼物!',
'F2' => '被男神强势壁咚!',
'F3' => '腿细胸大屁股翘!',
'F4' => '任何style都轻松驾驭!'
);
return $data[$type];
}
/**
* 检测登录状态
*
* @return int
*/
private function getLoggedUid()
{
if ($this->_isApp) {
$uid = $this->get('uid');
} else {
$uid = $this->getUid();
}
return $uid;
}
/**
* 判断是否是APP访问
*
* @return bool
*/
private function isApp()
{
return (null !== $this->get('app_version'));
}
/**
* 判断是否需要微信分享
* @return bool
*/
private function checkNeedShare()
{
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false || $this->_isApp) {
return true;
}
return false;
}
/**
* 加密字符串
*
* @param string $data 需要加密的字符串
* @return string 加密之后的字符串
*/
private function encrypt($data)
{
$data = strval($data);
$key = md5(self::ENCRYPT_KEY);
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = '';
$str = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= $key{$x};
$x++;
}
for ($i = 0; $i < $len; $i++) {
$str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
}
return base64_encode($str);
}
/**
* 解密字符串
*
* @param string $data 需要解密的字符串
* @return string 解密之后的字符串
*/
private function decrypt($data)
{
$key = md5(self::ENCRYPT_KEY);
$x = 0;
$data = base64_decode($data);
$len = strlen($data);
$l = strlen($key);
$char = '';
$str = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
} else {
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return $str;
}
}
... ...