composer是依赖管理工具。
有时我们会在一个项目中使用到多个composer,且每个版本不同。
前提:例如项目xyz根目录vendor中存在阿里云的对应代码。我现在需要再composer腾讯云短信发送的SDK。
1、随便找个位置新建文件夹,存储腾讯云短信发送的SDK。(/vendorten)
2、替换composer代码:根目录中的composer.json内容替换成下面代码。这个代码可以腾讯云官网文档中下载到
{
"name": "tencentcloud/sample",
"description": "Tencent Cloud SDK PHP code sample.",
"type": "library",
"license": "Apache 2.0",
"require": {
"php": ">=5.6",
"tencentcloud/common": "*",
"tencentcloud/sms" : "*",
"guzzlehttp/psr7": "^2.7"
},
"authors": [
{
"name": "tencentcloudapi",
"email": "tencentcloudapi@tencent.com"
}
],
"config": {
"secure-http": false
}
}
3、执行composer代码:我这边使用宝塔安装的composer执行。需要注意这边执行后的代码会存储到vendor中。到时把vendor中的所有代码拷贝到vendorten中就可以
4、使用:代码中引用vendorten中的autoload.php就可以正常使用腾讯云短信发送了
$lotusHome = ROOT_PATH . "vendortencent" . DIRECTORY_SEPARATOR;
$a=$lotusHome.'autoload.php';
include_once $a;
set_time_limit(0);
try {
$cred = new \TencentCloud\Common\Credential($sms["txy_secretid"],$sms["txy_secretkey"]);
$client=new \TencentCloud\Sms\V20190711\SmsClient($cred,"");
$req = new \TencentCloud\Sms\V20190711\Models\SendSmsRequest();
//短信应用ID
$req->SmsSdkAppid = $sms["txy_appid"];
//短信签名内容
$req->Sign =$sms["txy_sign"];
//手机号码
$req->PhoneNumberSet=["+86".$phone];
//模板ID
$req->TemplateID = $sendid;
//模板参数
if(count($data)>0){
$req->TemplateParamSet = $data;
}
$resp = $client->SendSms($req);
print_r($resp->toJsonString());
}catch (\Exception $e){
echo $e;
}