12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace service;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- class AliMessageService
- {
-
- public static function init()
- {
- AlibabaCloud::accessKeyClient(SystemConfigService::get('accessKeyId'), SystemConfigService::get('accessKeySecret'))
- ->regionId('cn-hangzhou')
- ->asDefaultClient();
- }
-
- public static function sendmsg($tel = '', $setTemplateParam = [], $setOutId = '')
- {
- try {
- self::init();
- $result = AlibabaCloud::rpc()
- ->product('Dysmsapi')
- ->version('2017-05-25')
- ->action('SendSms')
- ->method('POST')
- ->host('dysmsapi.aliyuncs.com')
- ->options([
- 'query' => [
- 'RegionId' => "cn-hangzhou",
- 'PhoneNumbers' => $tel,
- 'SignName' => SystemConfigService::get('smsSignName'),
- 'TemplateCode' => SystemConfigService::get('smsTemplateCode'),
- 'TemplateParam' => json_encode(is_array($setTemplateParam) ? $setTemplateParam : ['code' => $setTemplateParam]),
- ],
- ])->request()->toArray();
- return $result;
- } catch (ClientException $e) {
- return false;
- } catch (ServerException $e) {
- return false;
- }
- }
-
- public static function getVerificationCode($length = 6)
- {
- $str = '123456789';
- $code = '';
- for ($i = 0; $i < $length; $i++) {
- $code .= $str[mt_rand(0, strlen($str) - 1)];
- }
- return $code;
- }
- }
|