<?php
namespace extend\alisms;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\Tea\Utils\Utils;

class Sms 
{
     /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => $accessKeyId,
            // 您的AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function sendVerify($phone,$vcode){
        $client = self::createClient("LTAI4FmSkDSwFuXeLxsDB3jB", "r8FfRmoeWcCJyZSqqkQP2G3dKPPl2N");
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $phone,
            "signName" => "华连云",
            "templateCode" => "SMS_483310379",
            "templateParam" => "{\"code\":\"$vcode\"}"
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $sendResp = $client->sendSms($sendSmsRequest);
        $code = $sendResp->body->code;
        if (!Utils::equalString($code, "OK")) {
            $return_info = [
                'code' => 0,
                'msg' => $sendResp->body->message
            ];
            return $return_info;
        }

        return  ['code' => 1];

    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function sendToCashout($phone,$data){
        $client = self::createClient("LTAI4FmSkDSwFuXeLxsDB3jB", "r8FfRmoeWcCJyZSqqkQP2G3dKPPl2N");
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $phone,
            "signName" => "河南华连网络科技",
            "templateCode" => "SMS_462280213",
            "templateParam" => json_encode($data)
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $sendResp = $client->sendSms($sendSmsRequest);
        $code = $sendResp->body->code;
        if (!Utils::equalString($code, "OK")) {
            $return_info = [
                'code' => 0,
                'msg' => $sendResp->body->message
            ];
            return $return_info;
        }

        return  ['code' => 1];

    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function sendToBalance($phone,$data){
        $client = self::createClient("LTAI4FmSkDSwFuXeLxsDB3jB", "r8FfRmoeWcCJyZSqqkQP2G3dKPPl2N");
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $phone,
            "signName" => "河南华连网络科技",
            "templateCode" => "SMS_463687988",
            "templateParam" => json_encode($data)
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $sendResp = $client->sendSms($sendSmsRequest);
        $code = $sendResp->body->code;
        if (!Utils::equalString($code, "OK")) {
            $return_info = [
                'code' => 0,
                'msg' => $sendResp->body->message
            ];
            return $return_info;
        }

        return  ['code' => 1];

    }
}