Commit 7b4356b1 authored by jianghaiming's avatar jianghaiming

update:修改冲突

parents bb87474f 91132a3f
...@@ -9,7 +9,7 @@ use App\Exception\BaseException; ...@@ -9,7 +9,7 @@ use App\Exception\BaseException;
class UserException extends BaseException class UserException extends BaseException
{ {
protected $base_code = Code::USUR; protected $base_code = Code::USUR;
const APP_ID_NULL = 15;
protected $cus = [ protected $cus = [
0 => 'code 无效', 0 => 'code 无效',
1 => '获取openid失败', 1 => '获取openid失败',
...@@ -26,5 +26,6 @@ class UserException extends BaseException ...@@ -26,5 +26,6 @@ class UserException extends BaseException
12 => '绑定手机号保存失败', 12 => '绑定手机号保存失败',
13 => '请求太频繁,稍后重试', 13 => '请求太频繁,稍后重试',
14 => '手机号格式错误', 14 => '手机号格式错误',
self::APP_ID_NULL => 'AppId 不能为空',
]; ];
} }
\ No newline at end of file
...@@ -37,19 +37,15 @@ class UserService ...@@ -37,19 +37,15 @@ class UserService
public static function wechatLogin($params) public static function wechatLogin($params)
{ {
self::$code = !empty($params['code']) ? $params['code'] : '';//小程序授权code self::$code = !empty($params['code']) ? $params['code'] : '';//小程序授权code
$appid = !empty($params['appid']) ? $params['appid'] : 1; //登陆来源 $appid = !empty($params['appid']) ? $params['appid'] : ''; //登陆来源
$inviteUserId = !empty($params['invite_user_id']) ? intval($params['invite_user_id']) : 0;//邀请用户id $inviteUserId = !empty($params['invite_user_id']) ? intval($params['invite_user_id']) : 0;//邀请用户id
$activityType = !empty($params['activity_type']) ? intval($params['activity_type']) : 0;//活动类型 $activityType = !empty($params['activity_type']) ? intval($params['activity_type']) : 0;//活动类型
if (empty(self::$code)) { //验证登陆参数
FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE), '', 'jianghaiming@yidian-inc.com'); self::checkWechatLoginParams($params);
throw new UserException(['cus' => 0]);
}
$lock = self::getWechatLoginLock($params); $lock = self::getWechatLoginLock($params);
if(!empty($lock)){ if(!empty($lock)){
return $lock; return $lock;
} }
//设置小程序配置 //设置小程序配置
self::setWechatConfig($appid); self::setWechatConfig($appid);
//获取小程序用户信息 //获取小程序用户信息
...@@ -103,6 +99,22 @@ class UserService ...@@ -103,6 +99,22 @@ class UserService
return $user; return $user;
} }
/**
* 验证登陆参数
* @param $params
* @throws UserException
*/
public static function checkWechatLoginParams($params)
{
if (empty(self::$code)) {
FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE), '', 'jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 0]);
}
if (empty($params['appid'])) {
throw new UserException(['cus' => UserException::APP_ID_NULL]);
}
}
/** /**
* 初始化微信配置 * 初始化微信配置
* @param $wechatFrom * @param $wechatFrom
...@@ -110,13 +122,8 @@ class UserService ...@@ -110,13 +122,8 @@ class UserService
public static function setWechatConfig($wechatFrom) public static function setWechatConfig($wechatFrom)
{ {
//需要授权微信 //需要授权微信
if ($wechatFrom == 'merchant-pub-deliverer') { self::$appid = \Yaf\Registry::get('config')->wechat->appid->$wechatFrom;
self::$appid = \Yaf\Registry::get('config')->deliverer->wechat->appid; self::$secret = \Yaf\Registry::get('config')->wechat->secret->$wechatFrom;
self::$secret = \Yaf\Registry::get('config')->deliverer->wechat->secret;
}else{
self::$appid = \Yaf\Registry::get('config')->wechat->appid;
self::$secret = \Yaf\Registry::get('config')->wechat->secret;
}
} }
/** /**
...@@ -186,6 +193,8 @@ class UserService ...@@ -186,6 +193,8 @@ class UserService
public static function bindPhone($params){ public static function bindPhone($params){
self::$openid = !empty($params['openid']) ? $params['openid'] : ''; self::$openid = !empty($params['openid']) ? $params['openid'] : '';
$phone = !empty($params['mobile']) ? $params['mobile'] : ''; $phone = !empty($params['mobile']) ? $params['mobile'] : '';
$wechatFrom = !empty($params['appid']) ? $params['appid'] : '';
self::setWechatConfig($wechatFrom);
if (!empty($phone)){ if (!empty($phone)){
$userInfo = self::delivererBindPhone($params); $userInfo = self::delivererBindPhone($params);
}else{ }else{
...@@ -268,8 +277,6 @@ class UserService ...@@ -268,8 +277,6 @@ class UserService
{ {
$encryptedData = !empty($params['encryptedData']) ? $params['encryptedData'] : ''; $encryptedData = !empty($params['encryptedData']) ? $params['encryptedData'] : '';
$iv = !empty($params['iv']) ? $params['iv'] : ''; $iv = !empty($params['iv']) ? $params['iv'] : '';
$appid = \Yaf\Registry::get('config')->wechat->appid;
if (!$encryptedData) { if (!$encryptedData) {
FileLog::error("bindPhone:encryptedData 为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com'); FileLog::error("bindPhone:encryptedData 为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 3]); throw new UserException(['cus' => 3]);
...@@ -290,7 +297,7 @@ class UserService ...@@ -290,7 +297,7 @@ class UserService
//解密 //解密
$decryptData = []; $decryptData = [];
$wXBizDataCrypt = new WxBizDataCrypt($appid, $sessionKey); $wXBizDataCrypt = new WxBizDataCrypt(self::$appid, $sessionKey);
$errCode = $wXBizDataCrypt->decryptData($encryptedData, $iv, $decryptData); $errCode = $wXBizDataCrypt->decryptData($encryptedData, $iv, $decryptData);
if ($errCode) { if ($errCode) {
......
...@@ -22,6 +22,16 @@ wechat.appid = "wx4e0d92499185fb74"; ...@@ -22,6 +22,16 @@ wechat.appid = "wx4e0d92499185fb74";
wechat.secret = "731bcf2f7ebb1ebddb677618c2008b25"; wechat.secret = "731bcf2f7ebb1ebddb677618c2008b25";
wechat.appid.merchant-pub-pin = "wx4e0d92499185fb74"
wechat.secret.merchant-pub-pin = "731bcf2f7ebb1ebddb677618c2008b25"
wechat.appid.merchant-pub-deliverer = "wx91042f2a75f8b994"
wechat.secret.merchant-pub-deliverer = "09d7ea5472d871b4b1a0f3100bdfe1c9"
wechat.appid.merchant-pub-idle = "wx415fe9cb54be1e09"
wechat.secret.merchant-pub-idle = "b1badcd547f47a456f400016af90b46f"
deliverer.wechat.appid = "wx91042f2a75f8b994"; deliverer.wechat.appid = "wx91042f2a75f8b994";
deliverer.wechat.secret = "09d7ea5472d871b4b1a0f3100bdfe1c9"; deliverer.wechat.secret = "09d7ea5472d871b4b1a0f3100bdfe1c9";
......
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