{"id":37016976,"url":"https://github.com/qcloudsms/qcloudsms_java","last_synced_at":"2026-01-14T01:56:33.283Z","repository":{"id":43612322,"uuid":"104997012","full_name":"qcloudsms/qcloudsms_java","owner":"qcloudsms","description":"Qcloudsms Java SDK","archived":false,"fork":false,"pushed_at":"2021-06-04T01:07:50.000Z","size":13022,"stargazers_count":171,"open_issues_count":2,"forks_count":105,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-07-08T08:51:56.924Z","etag":null,"topics":["java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qcloudsms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-27T09:07:28.000Z","updated_at":"2025-01-13T15:41:22.000Z","dependencies_parsed_at":"2022-09-08T03:00:22.562Z","dependency_job_id":null,"html_url":"https://github.com/qcloudsms/qcloudsms_java","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/qcloudsms/qcloudsms_java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcloudsms%2Fqcloudsms_java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcloudsms%2Fqcloudsms_java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcloudsms%2Fqcloudsms_java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcloudsms%2Fqcloudsms_java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qcloudsms","download_url":"https://codeload.github.com/qcloudsms/qcloudsms_java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcloudsms%2Fqcloudsms_java/sbom","scorecard":{"id":752971,"data":{"date":"2025-08-11","repo":{"name":"github.com/qcloudsms/qcloudsms_java","commit":"26a7cef0ebc2b18cf847010b6f11e13412507908"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 1/20 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":7,"reason":"binaries present in source code","details":["Warn: binary detected: releases/qcloudsms-1.0.6-javadoc.jar:1","Warn: binary detected: releases/qcloudsms-1.0.6-sources.jar:1","Warn: binary detected: releases/qcloudsms-1.0.6.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 17 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-7r82-7xv7-xcpj","Warn: Project is vulnerable to: GHSA-3vqj-43w4-2q58","Warn: Project is vulnerable to: GHSA-4jq9-2xhw-jpx7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T20:50:36.176Z","repository_id":43612322,"created_at":"2025-08-22T20:50:36.176Z","updated_at":"2025-08-22T20:50:36.176Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java"],"created_at":"2026-01-14T01:56:32.697Z","updated_at":"2026-01-14T01:56:33.277Z","avatar_url":"https://github.com/qcloudsms.png","language":"Java","readme":"腾讯云短信 Java SDK\n===\n\n## 腾讯短信服务\n\n目前`腾讯云短信`为客户提供`国内短信`、`国内语音`和`海外短信`三大服务，腾讯云短信SDK支持以下操作：\n\n### 国内短信\n\n国内短信支持操作：\n\n- 指定模板单发短信\n- 指定模板群发短信\n- 拉取短信回执和短信回复状态\n\n\u003e `Note` 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387)开通权限，量大客户可以使用此功能批量拉取，其他客户不建议使用。\n\n### 海外短信\n\n海外短信支持操作：\n\n- 指定模板单发短信\n- 指定模板群发短信\n- 拉取短信回执和短信回复状态\n\n\u003e `Note` 海外短信和国内短信使用同一接口，只需替换相应的国家码与手机号码，每次请求群发接口手机号码需全部为国内或者海外手机号码。\n\n### 语音通知\n\n语音通知支持操作：\n\n- 发送语音验证码\n- 发送语音通知\n- 上传语音文件\n- 按语音文件fid发送语音通知\n- 指定模板发送语音通知类\n\n## 开发\n\n### 准备\n\n在开始开发云短信应用之前，需要准备如下信息:\n\n- [x] 获取SDK AppID和AppKey\n\n云短信应用SDK `AppID`和`AppKey`可在[短信控制台](https://console.cloud.tencent.com/sms)的应用信息里获取，如您尚未添加应用，请到[短信控制台](https://console.cloud.tencent.com/sms)中添加应用。\n\n- [x] 申请签名\n\n一个完整的短信由短信`签名`和短信正文内容两部分组成，短信`签名`须申请和审核，`签名`可在[短信控制台](https://console.cloud.tencent.com/sms)的相应服务模块`内容配置`中进行申请。\n\n- [x] 申请模板\n\n同样短信或语音正文内容`模板`须申请和审核，`模板`可在[短信控制台](https://console.cloud.tencent.com/sms)的相应服务模块`内容配置`中进行申请。\n\n### 安装\n\nqcloudsms_java可以采用多种方式进行安装，我们提供以下三种方法供用户使用：\n\n#### maven\n\n要使用qcloudsms_java功能，需要在pom.xml中添加如下依赖：\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.qcloudsms\u003c/groupId\u003e\n  \u003cartifactId\u003eqcloudsms\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.6\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### sbt\n\n```\nlibraryDependencies += \"com.github.qcloudsms\" % \"sms\" % \"1.0.6\"\n```\n\n#### 其他\n\n- 方法1\n\n将[源代码](https://github.com/qcloudsms/qcloudsms_java/tree/master/src)直接引入到项目工程中。\n\n\u003e `Note` 由于qcloudsms_java依赖四个依赖项目library： [org.json](http://central.maven.org/maven2/org/json/json/20170516/json-20170516.jar) , [httpclient](http://central.maven.org/maven2/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar), [httpcore](http://central.maven.org/maven2/org/apache/httpcomponents/httpcore/4.4.7/httpcore-4.4.7.jar)和 [httpmine](http://central.maven.org/maven2/org/apache/httpcomponents/httpmime/4.5.3/httpmime-4.5.3.jar) 采用方法1需要将以上四个jar包导入工程。\n\n- 方法2\n\n将[JAR包](https://github.com/qcloudsms/qcloudsms_java/tree/master/releases/qcloudsms-1.0.6.jar)直接引入到您的工程中。\n\n\n### 文档\n\n若您对接口存在疑问，可以查阅:\n\n* [API开发指南](https://cloud.tencent.com/document/product/382/13297)\n* [SDK文档](https://qcloudsms.github.io/qcloudsms_java/)\n* [错误码](https://cloud.tencent.com/document/product/382/3771)\n\n### 示例\n\n- **准备必要参数**\n\n```java\n// 短信应用SDK AppID\nint appid = 1400009099; // 1400开头\n\n// 短信应用SDK AppKey\nString appkey = \"9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad\";\n\n// 需要发送短信的手机号码\nString[] phoneNumbers = {\"21212313123\", \"12345678902\", \"12345678903\"};\n\n// 短信模板ID，需要在短信应用中申请\nint templateId = 7839; // NOTE: 这里的模板ID`7839`只是一个示例，真实的模板ID需要在短信控制台中申请\n\n// 签名\nString smsSign = \"腾讯云\"; // NOTE: 这里的签名\"腾讯云\"只是一个示例，真实的签名需要在短信控制台中申请，另外签名参数使用的是`签名内容`，而不是`签名ID`\n```\n\n- **指定模板ID单发短信**\n\n```java\nimport com.github.qcloudsms.SmsSingleSender;\nimport com.github.qcloudsms.SmsSingleSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    String[] params = {\"5678\"};\n    SmsSingleSender ssender = new SmsSingleSender(appid, appkey);\n    SmsSingleSenderResult result = ssender.sendWithParam(\"86\", phoneNumbers[0],\n        templateId, params, smsSign, \"\", \"\");  // 签名不能为空串\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` 无论单发/群发短信还是指定模板ID单发/群发短信都需要从控制台中申请模板并且模板已经审核通过，才可能下发成功，否则返回失败。\n\n- **指定模板ID群发**\n\n```java\nimport com.github.qcloudsms.SmsMultiSender;\nimport com.github.qcloudsms.SmsMultiSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    String[] params = {\"5678\"};\n    SmsMultiSender msender = new SmsMultiSender(appid, appkey);\n    SmsMultiSenderResult result =  msender.sendWithParam(\"86\", phoneNumbers,\n        templateId, params, smsSign, \"\", \"\");  // 签名不能为空串\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` 群发一次请求最多支持200个号码，如有对号码数量有特殊需求请联系腾讯云短信技术支持(QQ:3012203387)。\n\u003e `Note` 无论单发/群发短信还是指定模板ID单发/群发短信都需要从控制台中申请模板并且模板已经审核通过，才可能下发成功，否则返回失败。\n\n- **发送语音验证码**\n\n```java\nimport com.github.qcloudsms.SmsVoiceVerifyCodeSender;\nimport com.github.qcloudsms.SmsVoiceVerifyCodeSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    SmsVoiceVerifyCodeSender vvcsender = new SmsVoiceVerifyCodeSender(appid,appkey);\n    SmsVoiceVerifyCodeSenderResult result = vvcsender.send(\"86\", phoneNumbers[0],\n        \"5678\", 2, \"\");\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` 语音验证码发送只需提供验证码数字，例如当msg=“5678”时，您收到的语音通知为“您的语音验证码是5678”，如需自定义内容，可以使用语音通知。\n\n- **发送语音通知**\n\n```java\nimport com.github.qcloudsms.SmsVoicePromptSender;\nimport com.github.qcloudsms.SmsVoicePromptSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    SmsVoicePromptSender vpsender = new SmsVoicePromptSender(appid, appkey);\n    SmsVoicePromptSenderResult result = vpsender.send(\"86\", phoneNumbers[0],\n        2, 2, \"5678\", \"\");\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n- **拉取短信回执以及回复**\n\n```java\nimport com.github.qcloudsms.SmsStatusPuller;\nimport com.github.qcloudsms.SmsStatusPullCallbackResult;\nimport com.github.qcloudsms.SmsStatusPullReplyResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    // Note: 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387)开通权限\n    int maxNum = 10;  // 单次拉取最大量\n    SmsStatusPuller spuller = new SmsStatusPuller(appid, appkey);\n\n    // 拉取短信回执\n    SmsStatusPullCallbackResult callbackResult = spuller.pullCallback(maxNum);\n    System.out.println(callbackResult);\n\n    // 拉取回复\n    SmsStatusPullReplyResult replyResult = spuller.pullReply(maxNum);\n    System.out.println(replyResult);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387)开通权限，量大客户可以使用此功能批量拉取，其他客户不建议使用。\n\n- **拉取单个手机短信状态**\n\n```java\nimport com.github.qcloudsms.SmsMobileStatusPuller;\nimport com.github.qcloudsms.SmsStatusPullCallbackResult;\nimport com.github.qcloudsms.SmsStatusPullReplyResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    int beginTime = 1511125600;  // 开始时间(unix timestamp)\n    int endTime = 1511841600;    // 结束时间(unix timestamp)\n    int maxNum = 10;             // 单次拉取最大量\n    SmsMobileStatusPuller mspuller = new SmsMobileStatusPuller(appid, appkey);\n\n    // 拉取短信回执\n    SmsStatusPullCallbackResult callbackResult = mspuller.pullCallback(\"86\",\n        phoneNumbers[0], beginTime, endTime, maxNum);\n    System.out.println(callbackResult);\n\n    // 拉取回复\n    SmsStatusPullReplyResult replyResult = mspuller.pullReply(\"86\",\n        phoneNumbers[0], beginTime, endTime, maxNum);\n    System.out.println(replyResult);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n- **发送国际短信**\n\n海外短信与国内短信发送类似, 发送海外短信只需替换相应国家码。\n\n\n- **上传语音文件**\n\n```java\nimport com.github.qcloudsms.VoiceFileUploader;\nimport com.github.qcloudsms.VoiceFileUploaderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\ntry {\n    // Note: 语音文件大小上传限制400K字节\n    String filePath = \"path/to/example.mp3\";\n    byte[] content = Files.readAllBytes(Paths.get(filePath));\n    VoiceFileUploader uploader = new VoiceFileUploader(appid, appkey);\n    VoiceFileUploaderResult result = uploader.upload(content, VoiceFileUploader.ContentType.MP3);\n    // 上传成功后，result里会带有语音文件的fid\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` '语音文件上传'功能需要联系腾讯云短信技术支持(QQ:3012203387)才能开通\n\n- **查询语音文件审核状态**\n\n```java\nimport com.github.qcloudsms.VoiceFileStatus;\nimport com.github.qcloudsms.VoiceFileStatusResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\ntry {\n    // Note: 这里fid来自`上传语音文件`接口返回的响应，要按语音\n    //       文件fid发送语音通知，需要先上传语音文件获取fid\n    String fid = \"c799d10a43ec109f02f2288ca3c85b79e7700c98.mp3\";\n    VoiceFileStatus vfstatus = new VoiceFileStatus(appid, appkey);\n    VoiceFileStatusResult result = vfstatus.get(fid);\n    // result里会带有语音文件审核状态status, {0: 待审核, 1: 通过, 2: 拒绝, 3: 语音文件不存在}\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` '查询语音文件审核状态'功能需要联系腾讯云短信技术支持(QQ:3012203387)才能开通\n\n\n- **按语音文件fid发送语音通知**\n\n```java\nimport com.github.qcloudsms.FileVoiceSender;\nimport com.github.qcloudsms.FileVoiceSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    // Note: 这里fid来自`上传语音文件`接口返回的响应，要按语音\n    //       文件fid发送语音通知，需要先上传语音文件获取fid\n    String fid = \"c799d10a43ec109f02f2288ca3c85b79e7700c98.mp3\";\n    FileVoiceSender fvsender = new FileVoiceSender(appid, appkey);\n    FileVoiceSenderResult result = fvsender.send(\"86\", phoneNumbers[0], fid, 2, \"\");\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n\u003e `Note` 按'语音文件fid发送语音通知'功能需要联系腾讯云短信技术支持(QQ:3012203387)才能开通\n\n\n- **指定模板发送语音通知**\n\n```java\nimport com.github.qcloudsms.TtsVoiceSender;\nimport com.github.qcloudsms.TtsVoiceSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n    int templateId = 45221;\n    String[] params = {\"5678\"};\n    TtsVoiceSender tvsender = new TtsVoiceSender(appid, appkey);\n    TtsVoiceSenderResult result = tvsender.send(\"86\", phoneNumbers[0],\n        templateId, params, 2, \"\");\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n#### 使用代理\n\n有的环境需要使用代理才能上网，可使用ProxyHTTPClient来发送请求, 示例如下:\n\n```java\nimport com.github.qcloudsms.SmsSingleSender;\nimport com.github.qcloudsms.SmsSingleSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport com.github.qcloudsms.httpclient.ProxyHTTPClient;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\ntry {\n   // 创建一个代理httpclient\n    ProxyHTTPClient httpclient = new ProxyHTTPClient(\"127.0.0.1\", 8080, \"http\");\n\n    String[] params = {\"5678\"};\n    SmsSingleSender ssender = new SmsSingleSender(appid, appkey, httpclient);\n    SmsSingleSenderResult result = ssender.sendWithParam(\"86\", phoneNumbers[0],\n        templateId, params, smsSign, \"\", \"\");  // 签名参数未提供或者为空时，会使用默认签名发送短信\n    System.out.println(result);\n} catch (HTTPException e) {\n    // HTTP响应码错误\n    e.printStackTrace();\n} catch (JSONException e) {\n    // json解析错误\n    e.printStackTrace();\n} catch (IOException e) {\n    // 网络IO错误\n    e.printStackTrace();\n}\n```\n\n#### 使用连接池\n\n多个线程可以共用一个连接池发送API请求，多线程并发单发短信示例如下：\n\n```java\nimport com.github.qcloudsms.SmsSingleSender;\nimport com.github.qcloudsms.SmsSingleSenderResult;\nimport com.github.qcloudsms.httpclient.HTTPException;\nimport com.github.qcloudsms.httpclient.PoolingHTTPClient;\nimport org.json.JSONException;\n\nimport java.io.IOException;\n\n\nclass SmsThread extends Thread {\n\n    private final SmsSingleSender sender;\n    private final String nationCode;\n    private final String phoneNumber;\n    private final String msg;\n\n    public SmsThread(SmsSingleSender sender, String nationCode, String phoneNumber, String msg) {\n        this.sender = sender;\n        this.nationCode = nationCode;\n        this.phoneNumber = phoneNumber;\n        this.msg = msg;\n    }\n\n    @Override\n    public void run() {\n        try {\n            SmsSingleSenderResult result = sender.send(0, nationCode, phoneNumber, msg, \"\", \"\");\n            System.out.println(result);\n        } catch (HTTPException e) {\n            // HTTP响应码错误\n            e.printStackTrace();\n        } catch (JSONException e) {\n            // json解析错误\n            e.printStackTrace();\n        } catch (IOException e) {\n            // 网络IO错误\n            e.printStackTrace();\n        }\n    }\n}\n\npublic class SmsTest {\n\n    public static void main(String[] args) {\n\n        int appid = 122333333;\n        String appkey = \"9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad\";\n        String[] phoneNumbers = {\n            \"21212313123\", \"12345678902\", \"12345678903\",\n            \"21212313124\", \"12345678903\", \"12345678904\",\n            \"21212313125\", \"12345678904\", \"12345678905\",\n            \"21212313126\", \"12345678905\", \"12345678906\",\n            \"21212313127\", \"12345678906\", \"12345678907\",\n        };\n\n        // 创建一个连接池httpclient, 并设置最大连接量为10\n        PoolingHTTPClient httpclient = new PoolingHTTPClient(10);\n\n        // 创建SmsSingleSender时传入连接池http client\n        SmsSingleSender ssender = new SmsSingleSender(appid, appkey, httpclient);\n\n        // 创建线程\n        SmsThread[] threads = new SmsThread[phoneNumbers.length];\n        for (int i = 0; i \u003c phoneNumbers.length; i++) {\n            threads[i] = new SmsThread(ssender, \"86\", phoneNumbers[i], \"您验证码是：5678\");\n        }\n\n        // 运行线程\n        for (int i = 0; i \u003c threads.length; i++) {\n            threads[i].start();\n        }\n\n        // join线程\n        for (int i = 0; i \u003c threads.length; i++) {\n            threads[i].join();\n        }\n\n        // 关闭连接池httpclient\n        httpclient.close();\n    }\n}\n```\n\n### 使用自定义HTTP client实现\n\n如果需要使用自定义的HTTP client实现，只需实现`com.github.qcloudsms.httpclient.HTTPClient`接口，并在构造API对象时传入自定义HTTP client即可，一个参考示例如下：\n\n```java\nimport com.github.qcloudsms.httpclient.HTTPClient;\nimport com.github.qcloudsms.httpclient.HTTPRequest;\nimport com.github.qcloudsms.httpclient.HTTPResponse;\n\nimport java.io.IOException;\nimport java.net.URISyntaxException;\n\n// import com.example.httpclient.MyHTTPClient\n// import com.exmaple.httpclient.MyHTTPRequest\n// import com.example.httpclient.MyHTTPresponse\n\n\npublic class CustomHTTPClient implements HTTPClient {\n\n    public HTTPResponse fetch(HTTPRequest request) throws IOException, URISyntaxException {\n        // 1. 创建自定义HTTP request\n        // MyHTTPrequest req = MyHTTPRequest.build(request)\n\n        // 2. 创建自定义HTTP cleint\n        // MyHTTPClient client = new MyHTTPClient();\n\n        // 3. 使用自定义HTTP client获取HTTP响应\n        // MyHTTPResponse response = client.fetch(req);\n\n        // 4. 转换HTTP响应到HTTPResponse\n        // HTTPResponse res = transformToHTTPResponse(response);\n\n        // 5. 返回HTTPResponse实例\n        // return res;\n    }\n\n    public void close() {\n        // 如果需要关闭必要资源\n    }\n}\n\n// 创建自定义HTTP client\nCustomHTTPClient httpclient = new CustomHTTPClient();\n// 构造API对象时传入自定义HTTP client\nSmsSingleSender ssender = new SmsSingleSender(appid, appkey, httpclient);\n```\n\n\u003e `Note` 注意上面的这个示例代码只作参考，无法直接编译和运行，需要作相应修改。\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqcloudsms%2Fqcloudsms_java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqcloudsms%2Fqcloudsms_java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqcloudsms%2Fqcloudsms_java/lists"}