<?php
namespace app\common\server;

use TencentCloud\Common\Credential;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Sms\V20210111\Models\SendSmsRequest;
use TencentCloud\Sms\V20210111\SmsClient;

class tencentcloudserver
{
    public function getconfig()
    {
        $config = [
            "SecretId" => 'AKIDRhiSv84j8H9j25sOdbJq77rKWR6TZOwE',
            "SecretKey" => 'ziANIxLbbNt87pGQLzMSIr9AuObfWoth',
            'region' => 'ap-beijing',
            'endpoint' => 'sms.tencentcloudapi.com',
        ];
        return $config;
    }
    /**
     * 发送短信
     *
     * @param  [type] $appid
     * @param  [type] $SignName
     * @param  [type] $TemplateId
     * @param  [type] $TemplateParamSet
     * @param  [type] $PhoneNumberSet
     * @return void
     * @author wj
     * @date 2022-07-26
     */
    public function sendsms($array)
    {
        try {
            $config = $this->getconfig();
            $cred = new Credential($config['SecretId'], $config['SecretKey']);
            $this->cred = $cred;
            $httpProfile = new HttpProfile();
            $httpProfile->setEndpoint($config['endpoint']);
            $clientProfile = new ClientProfile();
            $clientProfile->setHttpProfile($httpProfile);
            $client = new SmsClient($cred, $config['region'], $clientProfile);
            $req = new SendSmsRequest();
            $req->fromJsonString(json_encode($array));
            $resp = $client->SendSms($req);
            $respArray = $resp->serialize();
            $respArray = $respArray['SendStatusSet'][0];
            if ('Ok' != $respArray['Code']) {
                return backarr(0, $respArray['Message']);
            }
            return backarr(1, 'suceess');
        } catch (TencentCloudSDKException $e) {
            return backarr(0, $e->getMessage());
        }
    }

}
