12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\mobile\logic;
- //关于微信相关操作的工具类
- use think\exception\ValidateException;
- use think\facade\Validate;
- class WechatLogic
- {
- //获取微信网页授权URL
- //$param $callback string 微信回跳地址(接口已经默认url_encode处理,授权成功会有$_GET['code']值,可用于下个步骤)
- //$param $state string 重定向后会带上state参数(开发者可以填写a-zA-Z0-9的参数值,最多128字节)
- //$param $scope string 应用授权作用域(snsapi_base | snsapi_userinfo)
- public static function getOauthRedirect(string $callback = '', string $state = '', string $scope = 'snsapi_base'): string
- {
- $val = Validate::rule([
- 'callback|微信回跳地址' => 'require|url',
- 'state|携带参数' => 'require|length:1,255',
- 'scope|应用授权作用域' => 'require|in:snsapi_base,snsapi_userinfo'
- ]);
- if (!$val->check(['callback' => $callback, 'state' => $state, 'scope' => $scope])) throw new ValidateException($val->getError());
- $oauth = &load_wechat('Oauth');
- $rs = $oauth->getOauthRedirect($callback, $state, $scope);
- halt('调用成功', $rs);
- }
- }
|