Merge pull request 'dev' (#8) from dev into master
Reviewed-on: http://git.excellentkk.cn/mkm/shop-php/pulls/8
This commit is contained in:
commit
d76b3fa9d6
@ -309,6 +309,63 @@ class Auth extends BaseController
|
||||
return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号用户绑定微信账号
|
||||
* @param UserRepository $repository
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function bindMp(UserRepository $repository)
|
||||
{
|
||||
list($code, $post_cache_key, $phone) = $this->request->params([
|
||||
'code',
|
||||
'cache_key',
|
||||
'phone',
|
||||
], true);
|
||||
$userInfoCong = Cache::get('eb_api_code_' . $code);
|
||||
if (!$code && !$userInfoCong)
|
||||
return app('json')->fail('授权失败,参数有误');
|
||||
$miniProgramService = MiniProgramService::create();
|
||||
if ($code && !$userInfoCong) {
|
||||
try {
|
||||
$userInfoCong = $miniProgramService->getUserInfo($code);
|
||||
Cache::set('eb_api_code_' . $code, $userInfoCong, 86400);
|
||||
} catch (Exception $e) {
|
||||
return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
$data = $this->request->params([
|
||||
['spread_spid', 0],
|
||||
['spread_code', ''],
|
||||
['iv', ''],
|
||||
['encryptedData', ''],
|
||||
]);
|
||||
try {
|
||||
//解密获取用户信息
|
||||
$userInfo = $miniProgramService->encryptor($userInfoCong['session_key'], $data['iv'], $data['encryptedData']);
|
||||
} catch (Exception $e) {
|
||||
if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
|
||||
throw $e;
|
||||
}
|
||||
if (!$userInfo) return app('json')->fail('openid获取失败');
|
||||
if (!isset($userInfo['openId'])) $userInfo['openId'] = $userInfoCong['openid'] ?? '';
|
||||
$userInfo['unionId'] = $userInfoCong['unionid'] ?? $userInfo['unionId'] ?? '';
|
||||
if (!$userInfo['openId']) return app('json')->fail('openid获取失败');
|
||||
/** @var WechatUserRepository $make */
|
||||
$make = app()->make(WechatUserRepository::class);
|
||||
$user = $make->syncRoutineUser($userInfo['openId'], $userInfo, false);
|
||||
if (!$user) {
|
||||
return app('json')->fail('授权失败');
|
||||
}
|
||||
$userInDb = $repository->accountByUser($phone);
|
||||
if ($userInDb->save(['wechat_user_id' => $user[0]['wechat_user_id']]) === false) {
|
||||
return app('json')->fail('授权失败');
|
||||
}
|
||||
return app('json')->success();
|
||||
}
|
||||
|
||||
public function getCaptcha()
|
||||
{
|
||||
$codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
|
||||
|
@ -6,7 +6,7 @@ use crmeb\basic\BaseController;
|
||||
|
||||
class StoreMicro extends BaseController
|
||||
{
|
||||
function seach_bar_code($code='',$name='',$mer_id){
|
||||
function seach_bar_code($mer_id,$code='',$name=''){
|
||||
$category_id=Db::name('merchant')->where('mer_id',$mer_id)->value('category_id');
|
||||
$mer_id=Db::name('merchant')->where('category_id',$category_id)->where('type_id',13)->value('mer_id');
|
||||
if($code!=''){
|
||||
@ -28,6 +28,17 @@ class StoreMicro extends BaseController
|
||||
return app('json')->success($store_product);
|
||||
}
|
||||
|
||||
public function ProductDetails($id){
|
||||
$find=Db::name('store_product')->where('product_id',$id)
|
||||
->withAttr('attr_value',function ($value,$data){
|
||||
return Db::name('store_product_attr_value')->where('product_id',$data['product_id'])->select();
|
||||
})
|
||||
->find();
|
||||
return app('json')->success(['list'=>$find]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function eadtProduct(){
|
||||
$product_id = $this->request->param('id', 0);
|
||||
if ($product_id==0) return app('json')->fail('商品id不能为空');
|
||||
|
@ -26,6 +26,7 @@ Route::group('api/', function () {
|
||||
|
||||
Route::group('micro', function () {
|
||||
Route::get('seach_bar_code', '/seach_bar_code');
|
||||
Route::get('product_details', '/ProductDetails');
|
||||
Route::post('eadt_product', '/eadtProduct');
|
||||
})->prefix('api.store.product.StoreMicro');
|
||||
|
||||
@ -595,6 +596,8 @@ Route::group('api/', function () {
|
||||
Route::get('auth/wechat', 'api.Auth/auth');
|
||||
//小程序授权
|
||||
Route::post('auth/mp', 'api.Auth/mpAuth');
|
||||
//绑定小程序账号
|
||||
Route::post('auth/bindMp', 'api.Auth/bindMp');
|
||||
//app授权
|
||||
Route::post('auth/app', 'api.Auth/appAuth');
|
||||
//apple授权
|
||||
|
Loading…
x
Reference in New Issue
Block a user