| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\controller\mini;
- use app\extra\basic\Base;
- use app\extra\douyin\Client;
- use app\extra\douyin\Crypt;
- use app\extra\tools\CodeExtend;
- use app\model\saas\SaasMember;
- use app\model\saas\SaasOrderLife;
- use app\model\saas\SaasOrderLog;
- use app\model\saas\SaasStore;
- use LinFly\Annotation\Route\Controller;
- use LinFly\Annotation\Route\Route;
- use support\Request;
- use support\Response;
- use Shopwwi\WebmanAuth\Auth as AuthMode;
- #[Controller(prefix: "/api/dy/home")]
- class Auth extends Base
- {
- #[Route(path: "license",methods: "post")]
- public function getLicense(): Response
- {
- try {
- return success("ok",[
- "img" => "https://hx-mini.jsshuita.com.cn/license.jpg"
- ]);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- /**
- * @param Request $request
- * @return Response
- */
- #[Route(path: "login",methods: "post")]
- public function setLogin(Request $request): Response
- {
- try {
- $param = $request->post();
- $sessionKey = (new Crypt)->config($this->getDyConfig())->getSessionKey($param['auth']);
- if (!isset($sessionKey['openid'])) return error("获取数据失败");
- $openId = $sessionKey['openid'];
- $userIn = [
- 'open_id' => $openId,
- "create_ip" => $request->getRealIp(),
- // "nickname" => "用户_".strtoupper(CodeExtend::random(3,5)),
- "avatar" => "https://img.inmei.cc/logo.png"
- ];
- $user = (new SaasMember)->where("open_id",$openId)->findOrEmpty();
- $userIn['id'] = $user['id'];
- if ($user->isEmpty()) {
- $userIn['id'] = $user->insertGetId($userIn);
- }
- // 同步已经下单的订单
- if (!empty($param['account_id'])) {
- $this->asyncDyOrder($param['account_id'],$openId);
- }
- return successTrans("success.data",[
- "user" => get_object_vars((new AuthMode)->guard("member")->login($userIn)),
- "coupon" => (new SaasOrderLife)->with(['goods' => function($query){
- $query->field("out_id,product_img");
- },'store' => function($query){
- $query->field("store_id,service_mobile");
- }])->append(['expire_at'])->withAttr(['expire_at' => function($data,$resp){
- return date("Y-m-d",strtotime($resp['expire_at']));
- }])->where("open_id",$openId)->where("status",1)->select()
- ]);
- } catch (\Throwable $throwable) {
- echo getDateFull()."==授权登陆===".$throwable->getMessage()."\n";
- echo getDateFull()."==授权登陆===".$throwable->getFile()."\n";
- echo getDateFull()."==授权登陆===".$throwable->getLine()."\n";
- return error($throwable->getMessage());
- }
- }
- protected function decrypt2code($private_key, $ciphertext_str) {
- // 解码 base64 密文
- $ciphertext = base64_decode($ciphertext_str);
- // 使用私钥解密
- openssl_private_decrypt($ciphertext, $plaintext, $private_key, OPENSSL_PKCS1_PADDING);
- if ($plaintext === false) {
- return [];
- }
- return json_decode($plaintext,true);
- }
- protected function decrypt($encrypted_data, $session_key, $iv) {
- $data = base64_decode($encrypted_data);
- $key = base64_decode($session_key);
- $iv_decoded = base64_decode($iv);
- // 使用 AES-256-CBC 模式解密
- return openssl_decrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv_decoded);
- }
- }
|