|
@@ -12,6 +12,7 @@ use app\Request;
|
|
|
use EasyWeChat\Factory;
|
|
|
use library\lib\weixina;
|
|
|
use library\services\UtilService;
|
|
|
+use library\services\MiniProgramService;
|
|
|
use think\db\exception\DbException;
|
|
|
use think\db\exception\PDOException;
|
|
|
use think\Exception;
|
|
@@ -32,6 +33,9 @@ class Weixin extends BaseController
|
|
|
return app('json')->success($jssdk);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 公众号获取微信信息
|
|
|
+ */
|
|
|
public function getInfo(Request $request)
|
|
|
{
|
|
|
$code = trim($request->get('code'));
|
|
@@ -55,6 +59,34 @@ class Weixin extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 小程序授权登录
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ * @throws \Psr\SimpleCache\InvalidArgumentException
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function mp_auth(Request $request){
|
|
|
+ $code = trim($request->post('code'));
|
|
|
+ if (!$code)
|
|
|
+ return app('json')->fail('授权失败,参数有误');
|
|
|
+ try {
|
|
|
+ $appid = "wxb4c2433f398a6a48";
|
|
|
+ $secret = "3fb376e8197f3fb9670644adbcabae59";
|
|
|
+ $c= file_get_contents("https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$code."&grant_type=authorization_code");
|
|
|
+ dump(json_encode($c));//对JSON格式的字符串进行编码
|
|
|
+
|
|
|
+// $userInfoCong = MiniProgramService::getUserInfo($code);
|
|
|
+// $session_key = $userInfoCong['session_key'];
|
|
|
+// $openid = $userInfoCong['openid'];
|
|
|
+// $unionid = $userInfoCong['unionid'];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param Request $request
|
|
|
*/
|