tencentcloudserver.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\server;
  3. use TencentCloud\Common\Credential;
  4. use TencentCloud\Common\Exception\TencentCloudSDKException;
  5. use TencentCloud\Common\Profile\ClientProfile;
  6. use TencentCloud\Common\Profile\HttpProfile;
  7. use TencentCloud\Sms\V20210111\Models\SendSmsRequest;
  8. use TencentCloud\Sms\V20210111\SmsClient;
  9. class tencentcloudserver
  10. {
  11. public function getconfig()
  12. {
  13. $config = [
  14. "SecretId" => 'AKIDRhiSv84j8H9j25sOdbJq77rKWR6TZOwE',
  15. "SecretKey" => 'ziANIxLbbNt87pGQLzMSIr9AuObfWoth',
  16. 'region' => 'ap-beijing',
  17. 'endpoint' => 'sms.tencentcloudapi.com',
  18. ];
  19. return $config;
  20. }
  21. /**
  22. * 发送短信
  23. *
  24. * @param [type] $appid
  25. * @param [type] $SignName
  26. * @param [type] $TemplateId
  27. * @param [type] $TemplateParamSet
  28. * @param [type] $PhoneNumberSet
  29. * @return void
  30. * @author wj
  31. * @date 2022-07-26
  32. */
  33. public function sendsms($array)
  34. {
  35. try {
  36. $config = $this->getconfig();
  37. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  38. $this->cred = $cred;
  39. $httpProfile = new HttpProfile();
  40. $httpProfile->setEndpoint($config['endpoint']);
  41. $clientProfile = new ClientProfile();
  42. $clientProfile->setHttpProfile($httpProfile);
  43. $client = new SmsClient($cred, $config['region'], $clientProfile);
  44. $req = new SendSmsRequest();
  45. $req->fromJsonString(json_encode($array));
  46. $resp = $client->SendSms($req);
  47. $respArray = $resp->serialize();
  48. $respArray = $respArray['SendStatusSet'][0];
  49. if ('Ok' != $respArray['Code']) {
  50. return backarr(0, $respArray['Message']);
  51. }
  52. return backarr(1, 'suceess');
  53. } catch (TencentCloudSDKException $e) {
  54. return backarr(0, $e->getMessage());
  55. }
  56. }
  57. }