Commit 060c5f0f by lizhilin

更新

parent da3a04d6
......@@ -5,7 +5,9 @@
use App\Command\Log;
use App\Models\PersonalAccessToken;
use App\Models\User;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
class LoginController extends BaseController
......@@ -115,19 +117,26 @@ public function merchantLogin(Request $request)
$code = $request->code ?? '';
if (!$code) {
return $this->JsonResponse('', '无效参数Code', 201);
return $this->JsonResponse('', '参数Code不能为空', 201);
}
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret=' . $secret . '&js_code=' . $code . '&grant_type=authorization_code';
$result = json_decode(file_get_contents($url), true);
if (isset($result['errcode'])) {
Log::add('商户端授权请求微信接口异常', $result);
return $this->JsonResponse('', '请求微信接口异常', 201);
}
$openId = $result['openid'];
if (!$muser->openid && $openId) {
$muser->openid = $openId;
$muser->save();
DB::beginTransaction();
try {
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret=' . $secret . '&js_code=' . $code . '&grant_type=authorization_code';
$result = json_decode(file_get_contents($url), true);
if (isset($result['errcode'])) {
Log::add('商户端授权请求微信接口异常', $result);
throw new \Exception($result['errmsg']);
}
$openId = $result['openid'];
if (!$muser->openid && $openId) {
$muser->openid = $openId;
$muser->save();
}
DB::commit();
} catch (\Exception $exception) {
DB::rollBack();
return $this->JsonResponse('', $exception->getMessage(), 201);
}
return $this->JsonResponse('');
......
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