Authored by 周少峰

address , coupon

<?php
/**
* 加密解密
*/
namespace WebPlugin;
class Encryption {
// 密钥
private static $key = '123';
// 加密
public static function encrypt ($data)
{
$char = '';
$str = '';
$key = md5(self::$key);
$x = 0;
$len = strlen($data);
$l = strlen($key);
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);
}
//解密
public static function decrypt($data)
{
$char = '';
$str = '';
$key = md5(self::$key);
$x = 0;
$data = base64_decode($data);
$len = strlen($data);
$l = strlen($key);
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;
}
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@
use Action\WebAction;
use WebPlugin\Helpers;
use WebPlugin\Encryption;
use Index\HomeModel;
use Index\CouponModel;
use LibModels\Web\Home\CouponData;
... ... @@ -29,7 +30,7 @@ class CouponController extends WebAction
* 领券页面控制器
*/
public function indexAction()
{
{
$channel = Helpers::getChannelNameByCookie();
//领券频道头部
$this->setWebNavHeader($channel);
... ... @@ -52,6 +53,11 @@ class CouponController extends WebAction
break;
}
$couponId = $this->get('id', '');
if (empty($couponId)) {
break;
}
//解密
$couponId = Encryption::decrypt($couponId);
$uid = $this->getUid();
if (!$uid) {
$playUrl = Helpers::url('/coupon/index');
... ...
... ... @@ -4,6 +4,7 @@ namespace Index;
use WebPlugin\Helpers;
use WebPlugin\Images;
use WebPlugin\Encryption;
use Index\HomeModel;
use LibModels\Web\Home\CouponData;
... ... @@ -60,7 +61,7 @@ class CouponModel
);
foreach ($couponlistval['data'] as $couponskey => $couponsval) {
$result['categories'][$i]['coupons'][$couponskey] = array(
'id' => $couponsval['couponID'], //优惠券号
'id' => Encryption::encrypt($couponsval['couponID']), //加密优惠券号
'img' => Images::getForceSourceUrl($couponsval['image']['src']), //优惠券图片
'url' => Helpers::getUrlSafe($couponsval['image']['url']) //去逛逛链接
);
... ...
... ... @@ -12,6 +12,7 @@ use WebPlugin\Images;
use Configs\WebCacheConfig;
use Hood\Core\Security\AuthCode;
use WebPlugin\UdpLog;
use WebPlugin\Encryption;
use Configs\ChannelConfig;
/**
... ... @@ -980,7 +981,7 @@ class CartModel
$mobile = substr($mobile, 0, 3) . '****' . substr($mobile, 7);
$build = array();
$build['id'] = $value['address_id'];
$build['id'] = Encryption::encrypt($value['address_id']);
$build['user'] = $value['consignee'];
$build['address'] = $value['area'] . $value['address'] . ' ' . $value['zip_code'] . ' ' . $mobile . ' ' . $value['phone'];
$build['checked'] = $value['is_default'] === 'Y';
... ...
... ... @@ -4,6 +4,7 @@ use Action\WebAction;
use WebPlugin\Helpers;
use Shopping\CartModel;
use WebPlugin\UdpLog;
use WebPlugin\Encryption;
/**
* 购物车相关的控制器
... ... @@ -269,6 +270,8 @@ class IndexController extends WebAction
if ($this->isAjax()) {
$uid = $this->getUid(false);
$addressId = $this->post('id');
//解密
$addressId = intval(Encryption::decrypt($addressId));
$result = CartModel::setDefaultAddress($uid, $addressId);
}
... ... @@ -295,7 +298,9 @@ class IndexController extends WebAction
if ($this->isAjax()) {
$uid = $this->getUid(false);
$id = $this->post('id', null);
$id = $this->post('id', null); //TODO
//解密
$id = intval(Encryption::decrypt($id));
$address = $this->post('address', '');
$areaCode = $this->post('areaCode', '');
$consignee = $this->post('consignee', '');
... ... @@ -327,7 +332,8 @@ class IndexController extends WebAction
if ($this->isAjax()) {
$uid = $this->getUid(false);
$addressId = $this->post('id');
$addressId = $this->post('id');// TODO
$addressId = intval(Encryption::decrypt($addressId));
$result = CartModel::delAddress($uid, $addressId);
}
... ... @@ -435,7 +441,9 @@ class IndexController extends WebAction
break;
}
$addressId = $this->post('addressId', null);
$addressId = $this->post('addressId', null);//TODO
//解密
$addressId = intval(Encryption::decrypt($addressId));
$cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车
$deliveryTimeId = $this->post('deliveryTimeId', 1); // 默认只工作日配送
$deliveryWayId = $this->post('deliveryWayId', 1); // 默认普通快递
... ...