Programlama diliniz için SDK'yı indirerek bir SMQ kuyruğundan mesaj alım bildirimlerini çekin.
SDK sürüm kılavuzu
Alibaba Cloud SMS, V1.0 SDK ve V2.0 SDK sunar. V2.0 SDK en güncel sürümdür ve V1.0 SDK ile aynı API özelliklerini sunar. V1.0 SDK'ya kıyasla, V2.0 SDK daha sağlamdır, kullanımı daha kolaydır ve daha fazla dili destekler. Ayrıca tek istemci iş parçacığı güvenliği sorununu çözer ve geliştirici deneyimini iyileştirir.
V1.0 SDK artık bakımı yapılmamaktadır. Hâlâ V1.0 kullanıyorsanız, V2.0 SDK'ya yükseltin.
SDK indirmeleri
Uluslararası SMS SDK'sı birden çok dili destekler. SDK kurulum yöntemlerini OpenAPI Portal'da bulabilirsiniz. Ayrıca GitHub'da kaynak kodları ve kurulum kılavuzlarını görüntüleyebilirsiniz. SDK'yı programlama diliniz için standart bağımlılık yönetim aracıyla yüklemenizi öneririz.
|
|
|
|
|
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|
||
|
|
|||
|
|
|
Mesaj alım örnekleri
Bir API çağrısı yapmadan önce SDK kimlik doğrulaması için ALIBABA_CLOUD_ACCESS_KEY_ID ve ALIBABA_CLOUD_ACCESS_KEY_SECRET ortam değişkenlerini yapılandırın. Ortam değişkenlerini yapılandırma adımları.
Java demo
package com.alicom.mns.sample;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.alicom.mns.tools.inter.DefaultAlicomMessagePuller;
import com.alicom.mns.tools.inter.MessageListener;
import com.aliyun.mns.model.Message;
/**
* This is the DEMO for SMS MNS Queue messages consumption
* MessageType: SmsReport
*/
public class ReceiveDemo {
static class MyMessageListener implements MessageListener {
@Override
public boolean dealMessage(Message message) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("message receiver time from mns:" + format.format(new Date()));
System.out.println("message handle: " + message.getReceiptHandle());
System.out.println("message body: " + message.getMessageBodyAsString());
System.out.println("message id: " + message.getMessageId());
System.out.println("message dequeue count:" + message.getDequeueCount());
System.out.println("Thread:" + Thread.currentThread().getName());
try {
//Please start your own code here
} catch (Throwable e) {
// The exception caused by your own code. Message will not be deleted and can be retrieved again
return false;
}
// Message will be deleted for the format error
return true;
}
}
public static void main(String[] args) {
DefaultAlicomMessagePuller puller = new DefaultAlicomMessagePuller();
//Set the size of asynchronous thread
puller.setConsumeMinThreadSize(6);
puller.setConsumeMaxThreadSize(16);
puller.setThreadQueueSize(200);
puller.setPullMsgThreadSize(1);
//Only enabled when debugging, should be disabled at working status
puller.openDebugLog(false);
String regionIdForPop = "ap-southeast-1";
String endpointNameForPop = "ap-southeast-1";
//If you are sending SMS requests to Singapore Region OpenAPI (domain: dysmsapi.ap-southeast-1.aliyuncs.com)
//Please use
String domainForPop = "dybaseapi.ap-southeast-1.aliyuncs.com";
String mnsAccountEndpoint = "http://1493622401794734.mns.ap-southeast-1.aliyuncs.com";
//If you are sending SMS requests to Indonesia Region(Jakarta) OpenAPI (domain: dysmsapi.ap-southeast-5.aliyuncs.com)
//Please use
//String domainForPop = "dybaseapi.ap-southeast-5.aliyuncs.com";
//String mnsAccountEndpoint = "http://1493622401794734.mns.ap-southeast-5.aliyuncs.com";
//If you are sending SMS requests to Germany Region(Frankfurt) OpenAPI (domain: dysmsapi.eu-central-1.aliyuncs.com)
//String domainForPop = "dybaseapi.eu-central-1.aliyuncs.com";
//String mnsAccountEndpoint = "http://1493622401794734.mns.eu-central-1.aliyuncs.com";
//If you are sending SMS requests to US East Region(Virginia) OpenAPI (domain: dysmsapi.us-east-1.aliyuncs.com)
//String domainForPop = "dybaseapi.us-east-1.aliyuncs.com";
//String mnsAccountEndpoint = "http://1493622401794734.mns.us-east-1.aliyuncs.com";
//AccessKey and SecretKey you can get if from Alibaba Cloud Console
String accessKeyId = "";
String accessKeySecret = "";
//SmsReport
String messageType = "SmsReport";
//QueueName you can get it from Alibaba Cloud Sms Console
//Pattern: Alicom-Queue-{UID}-{messageType}
String queueName = "";
puller.startReceiveMsgForVPC(accessKeyId, accessKeySecret, messageType, queueName, regionIdForPop,
endpointNameForPop, domainForPop, mnsAccountEndpoint, new MyMessageListener());
//or init your IAcsClient(accessKeySecret free)
//puller.startReceiveMsg(acsClient, messageType, queueName, new MyMessageListener(), mnsAccountEndpoint);
}
}
SSS
macOS'ta Python SDK entegre ederken "SSL: CERTIFICATE_VERIFY_FAILED" hatası
macOS üzerindeki Python SDK sunucu sertifikasını doğrulayamadığında websocket closed due to [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000) hatası oluşur.
Bu durum genellikle Python ortamınızda kök sertifikanın yapılandırılmamış olmasından kaynaklanır. Sorunu şu adımlarla çözün:
-
Sistem sertifikalarını dışa aktarın ve ortam değişkenlerini ayarlayın: Tüm macOS sistem sertifikalarını bir dosyaya dışa aktarın ve bunu varsayılan sertifika yolu olarak ayarlayın.
security find-certificate -a -p > ~/all_mac_certs.pem export SSL_CERT_FILE=~/all_mac_certs.pem export REQUESTS_CA_BUNDLE=~/all_mac_certs.pem -
Python OpenSSL yapılandırması için sembolik bağlantı oluşturun: Sistem SSL sertifikalarına bir sembolik bağlantı oluşturun. Yolu yerel makinenizde yüklü olan Python sürümüne göre değiştirin.
# 3.9 is an example version number. Adjust the path based on the Python version installed on your local machine. ln -s /etc/ssl/* /Library/Frameworks/Python.framework/Versions/3.9/etc/openssl Terminali yeniden başlatın ve önbelleği temizleyin: Ortam değişkenlerinin etkili olması için terminali kapatıp yeniden açın. Ardından olası önbelleği temizleyebilir ve WebSocket'e yeniden bağlanmayı deneyebilirsiniz.
Bu adımlardan sonra sorun devam ederse hedef sunucunun sertifika yapılandırmasını doğrulayın.