音乐第三方(腾讯正版曲库直通车)

官方文档:https://cloud.tencent.com/document/product/1155
腾讯曲库签名地址(id,key): https://cloud.tencent.com/document/api/213/30654

一、基本申请流程:


重点申请id和key地址:https://cloud.tencent.com/document/api/213/30654


切换子账号或继续使用,我点继续使用。

点击新建。

注意:新建后保存好之后会用。
回到API文档测试:https://cloud.tencent.com/document/product/1155/40100

填写自己创建的id and key 就可以测试了,因为没买曲,所以会没有什么数据。

二、SpringBoot接入曲库:

pom.xml

<properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><maven.compiler.encoding>UTF-8</maven.compiler.encoding><commons.version>3.11</commons.version><tencentcloud.version>3.1.217</tencentcloud.version><swagger2.version>2.9.2</swagger2.version><swagger-ui.sversion>1.9.6</swagger-ui.sversion></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--   腾讯第三方全家桶     --><dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>${tencentcloud.version}</version></dependency><!--    StringUtils    --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>${commons.version}</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>${swagger2.version}</version></dependency><dependency><groupId>com.github.xiaoymin</groupId><artifactId>swagger-bootstrap-ui</artifactId><version>${swagger-ui.sversion}</version></dependency></dependencies>

application.yml

lanys:music:#idsecretId: 输入自己的Id#keysecretKey: 输入自己的Key#购买歌曲后会需要将歌曲绑定域名,我使用它默认测试的endpoint: ame.tencentcloudapi.com#swaggerswagger:title: 牟某公司description: 牟某公司termsOfServiceUrl: http://eurasia.plus/swagger-ui.htmlContactName: xxxContactUrl: http://eurasia.plus/swagger-ui.htmlContactEmail: 1090613735@qq.comversion: 1.0packages: com.example.music_boot.controller
server:port: 8080servlet:context-path: /music

endpoint指域名,购买歌曲后会需要将歌曲绑定域名,我使用它默认测试的

Swagger配置

SwaggerProperties

@Data
@ConfigurationProperties("lanys.swagger")
public class SwaggerProperties {private String title;private String description;private String termsOfServiceUrl;private String ContactName;private String ContactUrl;private String ContactEmail;private String version;private String packages;
}

SwaggerConfig

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {@Bean@ConditionalOnMissingBeanpublic SwaggerProperties swaggerProperties(){return new SwaggerProperties();}@Beanpublic Docket createRestApi(SwaggerProperties swaggerProperties){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo(swaggerProperties)).enable(true).select().apis(RequestHandlerSelectors.basePackage(swaggerProperties.getPackages())).paths(PathSelectors.any()).build();}/*** 创建该API的基本信息(这些基本信息会展现在文档页面中)* 访问地址:http://项目实际地址/swagger-ui.html** @return*/private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {Contact contact = new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(),swaggerProperties.getContactEmail());return new ApiInfoBuilder().title(swaggerProperties.getTitle())//描述.description(swaggerProperties.getDescription()).termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl()).contact(contact).version(swaggerProperties.getVersion()).build();}
}

Result(自定义返回格式)

Result

@ApiModel(value = "返回值基本信息")
@Data
public class Result implements Serializable {private int code;private Object data;private String msg;public Result(int code, String msg) {this.code = code;this.msg = msg;}public Result(int code, Object data, String msg) {this.code = code;this.data = data;this.msg = msg;}public static Result success() {return new Result(ResultEnums.SUCCESS.getCode(), ResultEnums.SUCCESS.getMsg());}public static Result success(String data) {return new Result(ResultEnums.SUCCESS.getCode(), data, ResultEnums.SUCCESS.getMsg());}public static Result FAIL() {return new Result(ResultEnums.SUCCESS.getCode(), ResultEnums.SUCCESS.getMsg());}public static Result FAIL(String data) {return new Result(ResultEnums.SUCCESS.getCode(), data, ResultEnums.SUCCESS.getMsg());}public static Result EXCEPTION() {return new Result(ResultEnums.SUCCESS.getCode(), ResultEnums.SUCCESS.getMsg());}public static Result EXCEPTION(String data) {return new Result(ResultEnums.SUCCESS.getCode(), data, ResultEnums.SUCCESS.getMsg());}public Result put(Object data) {this.data = data;return this;}}

ResultEnums

@Getter
public enum ResultEnums {SUCCESS(200,"成功"),FAIL(500,"异常"),EXCEPTION(500,"失败");private int code;private  String msg;ResultEnums(int code, String msg) {this.code = code;this.msg = msg;}
}

MusicController

@Api(tags = "music接口")
@RestController
@RequestMapping("v1/music")
public class MusicController {@Autowiredprivate MusicFamilyMeals musicFamilyMeals;@PostMapping("/describe_auth_info")@ApiOperation("获取授权项目列表")@ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "limit", value = "页", dataType = "long"),@ApiImplicitParam(paramType = "query", name = "offset", value = "行", dataType = "long")})public Result describeAuthInfo(Long limit, Long offset) {if (limit == null || offset == null) {return Result.success().put(musicFamilyMeals.DescribeAuthInfo());}return Result.success().put(musicFamilyMeals.DescribeAuthInfo(limit, offset));}@ApiOperation("获取授权项目已购云音乐列表")@PostMapping("/describe_cloud_music")public Result describeCloudMusicPurchased() {return Result.success().put(musicFamilyMeals.DescribeCloudMusicPurchased());}@ApiOperation("获取云音乐播放信息")@PostMapping("describe_cloud_music ")@ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "musicId", value = "歌曲Id", dataType = "String")})public Result describeCloudMusic(String musicId) {if (StringUtils.isNotBlank(musicId)){return Result.success().put(musicFamilyMeals.describeCloudMusic(musicId));}return Result.FAIL("数据出现小问题");}@ApiOperation("获取已购曲库包列表")@PostMapping("/describe_packages")public Result describePackages() {return Result.success().put(musicFamilyMeals.describePackages());}@ApiOperation("获取曲库包歌曲播放信息")@PostMapping("describe_music")@ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "itemId", value = "歌曲ID", dataType = "String"),@ApiImplicitParam(paramType = "query", name = "offset", value = "在应用前端播放音乐C端用户的唯一标识。无需是账户信息,用户唯一标识即可", dataType = "String")})public Result describeMusic(String itemId, String identityId) {return Result.success().put(musicFamilyMeals.describeMusic(itemId, identityId));}@ApiOperation("获取歌词信息")@PostMapping("/describe_lyric")@ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "itemId", value = "歌曲id", dataType = "String")})public Result describeLyric(String itemId) {return Result.success().put(musicFamilyMeals.describeLyric(itemId));}@ApiOperation("根据歌曲ID查询歌曲信息")@PostMapping("/describe_Item_ById")@ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "itemId", value = "根据歌曲ID查询歌曲信息", dataType = "String")})public Result describeItemById(String itemId) {return Result.success().put(musicFamilyMeals.describeItemById(itemId));}@ApiOperation("搜索即时广播歌曲")@PostMapping("/search_ktv_musics")@ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "keyWord", value = "搜索关键词", dataType = "String"),@ApiImplicitParam(paramType = "query", name = "limit", value = "页", dataType = "long"),@ApiImplicitParam(paramType = "query", name = "offset", value = "行", dataType = "long")})public Result searchKTVMusics(String keyWord, Long limit, Long offset) {return Result.success().put(musicFamilyMeals.searchKTVMusics(keyWord, limit, offset));}
}

MusicFamilyMeals

@Slf4j
@Component
@NoArgsConstructor
public class MusicFamilyMeals {@Value("${lanys.music.secretId}")public String secretId;@Value("${lanys.music.secretKey}")public String secretKey;@Value("${lanys.music.endpoint}")public String endpoint;/*** 获取授权项目列表** @return*/public String DescribeAuthInfo() {try {Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeAuthInfoRequest req = new DescribeAuthInfoRequest();DescribeAuthInfoResponse resp = client.DescribeAuthInfo(req);return DescribeAuthInfoResponse.toJsonString(resp);} catch (TencentCloudSDKException e) {log.error("数据异常:" + e.toString());}return null;}/*** 获取授权项目已购云音乐列表 分页** @return*/public String DescribeAuthInfo(Long limit, Long offset) {try {Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeAuthInfoRequest req = new DescribeAuthInfoRequest();req.setLimit(limit);req.setOffset(offset);DescribeAuthInfoResponse resp = client.DescribeAuthInfo(req);return DescribeAuthInfoResponse.toJsonString(resp);} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 获取授权项目已购云音乐列表** @return*/public String DescribeCloudMusicPurchased() {try {Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeCloudMusicPurchasedRequest req = new DescribeCloudMusicPurchasedRequest();/*** 必加项目id*/req.setAuthInfoId("");DescribeCloudMusicPurchasedResponse resp = client.DescribeCloudMusicPurchased(req);System.out.println(DescribeCloudMusicPurchasedResponse.toJsonString(resp));} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 获取云音乐播放信息* @param musicId* @return*/public String describeCloudMusic(String musicId){try{Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeCloudMusicRequest req = new DescribeCloudMusicRequest();req.setMusicId(musicId);DescribeCloudMusicResponse resp = client.DescribeCloudMusic(req);System.out.println(DescribeCloudMusicResponse.toJsonString(resp));} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 获取已购曲库包列表* @return*/public String describePackages(){try{Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribePackagesRequest req = new DescribePackagesRequest();DescribePackagesResponse resp = client.DescribePackages(req);System.out.println(DescribePackagesResponse.toJsonString(resp));return DescribePackagesResponse.toJsonString(resp);} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 获取曲库包歌曲播放信息* @param itemId 歌曲ID* @param identityId 在应用前端播放音乐C端用户的唯一标识。无需是账户信息,用户唯一标识即可。* @return*/public String describeMusic(String itemId,String identityId){try{Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeMusicRequest req = new DescribeMusicRequest();req.setItemId(itemId);req.setIdentityId(identityId);DescribeMusicResponse resp = client.DescribeMusic(req);System.out.println(DescribeMusicResponse.toJsonString(resp));return DescribeMusicResponse.toJsonString(resp);} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 获取歌词信息* @param itemId 歌曲ID* @return*/public String describeLyric(String itemId){try{Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeLyricRequest req = new DescribeLyricRequest();//歌曲IDreq.setItemId(itemId);DescribeLyricResponse resp = client.DescribeLyric(req);System.out.println(DescribeLyricResponse.toJsonString(resp));return DescribeLyricResponse.toJsonString(resp);} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 根据歌曲ID查询歌曲信息* @param itemID  歌曲ID,目前暂不支持批量查询* @return*/public String describeItemById(String itemID ){try{Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);DescribeItemByIdRequest req = new DescribeItemByIdRequest();req.setItemIDs(itemID);DescribeItemByIdResponse resp = client.DescribeItemById(req);System.out.println(DescribeItemByIdResponse.toJsonString(resp));return DescribeItemByIdResponse.toJsonString(resp);} catch (TencentCloudSDKException e) {System.out.println(e.toString());}return null;}/*** 搜索即时广播歌曲* @param keyWord 搜索关键词* @param limit 分页游标* @param offset 分页页长* @return*/public String searchKTVMusics(String keyWord,Long limit,Long offset){Credential cred = new Credential(secretId, secretKey);HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(endpoint);ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);AmeClient client = new AmeClient(cred, "", clientProfile);//暂时没有该方法
//            SearchKTVMusicsRequest req = new SearchKTVMusicsRequest();
//
//            SearchKTVMusicsResponse resp = client.SearchKTVMusics(req);
//
//            System.out.println(SearchKTVMusicsResponse.toJsonString(resp));return null;}

项目没有很好优化,访问 doc.html ,http://127.0.0.1:8080/music/doc.html

{"code": 200,"data": "{\"AuthInfo\":[],\"TotalCount\":0,\"RequestId\":\"70f3f7be-2905-4072-9fa1-b53418ba9b72\"}","msg": "成功"
}

总结

项目充当个人笔记,第一次接入第三方服务(一般接入第三方有很多坑的,例如广播曲库的类依赖中没有。还要自己没有真正的使用,对于向第三方获取数据没有做处理等),但是最后公司因为曲库太贵了,就没买,所以项目没做优化,充当笔记。

音乐第三方(腾讯正版曲库直通车)相关推荐

  1. 声网在线K歌房解决方案:一站式接入版权曲库与K歌组件

    9月8日,实时互动云服务商声网Agora在北京举办主题为"K歌有声·想唱就唱"的发布会,正式发布了在线K歌房场景化解决方案,开发者与企业可一站式接入海量正版曲库与K歌组件.场景功能 ...

  2. 鸿蒙系统电视k歌,前沿讯息:华为电视K歌模式 开启当贝音乐 曲库任意选 功能很强大...

    科技.数码.互联网新闻如今都成为了大众所关注的热点了,眼下互联网.科技.数码已经与我们的生活息息相关,密不可分了.我们应该多为自己充电,多掌握些知识才能让自己见多识广,才能不断地提高自己的个人修为.. ...

  3. 将网易云音乐曲库路径指定到NAS

    标题背景 家有NAS一台,还有一台日常使用的电脑为Win10系统,已使用Windows自带的功能将SMB协议的文件夹共享映射为了一个盘符. 现在网易云音乐版权问题多,有的干脆没有,有的需要购买vip, ...

  4. 计算机音乐作品,关于建立声乐作品计算机音乐伴奏曲库的一些思考

    随着最近几年计算机技术的不断发展,计算机硬件系统的不断更新,计算机技术被广泛应用在各个技术领域.计算机音乐在专业音乐领域也不再是一门大家都不敢触碰的技术,它逐渐成为从事与音乐相关的工作者们谈论较多的学 ...

  5. 用计算机弹出画的伴奏,《体面》钢琴伴奏_关于建立声乐作品计算机音乐伴奏曲库的一些思考...

    随着最近几年计算机技术的不断发展,计算机硬件系统的不断更新,计算机技术被广泛应用在各个技术领域.计算机音乐在专业音乐领域也不再是一门大家都不敢触碰的技术,它逐渐成为从事与音乐相关的工作者们谈论较多的学 ...

  6. 网易云音乐是怎么做曲库缓存的?设计动机大揭秘!

    云音乐曲库缓存随着多年的实践.改善,结合曲库数据的特点,形成自有的一套缓存使用体系,并能够取得了很好的效果. 在工作过程中,有些喜欢刨根问底的同学会经常来讨论这样设计的原因,想在其它场景中借鉴一样的思 ...

  7. 免费听音乐软件,全网最全曲库

    全平台支持:Windows .Linux.Mac Listen 1 音乐播放器 Listen 1可以搜索和播放来自网易云音乐,QQ音乐,酷狗音乐,酷我音乐,Bilibili,咪咕音乐网站的歌曲,让你的 ...

  8. 网易云音乐VS腾讯音乐,1.0和2.0的交锋

    文 | 江户川柯镇恶 来源 | 螳螂财经(ID:TanglangFin) 音乐版权的话题,一直都很性感. 5月12日,腾讯音乐2020年Q1业绩出炉,付费用户达到4270万,同比增长50.4%,音乐订 ...

  9. 付费率、月活增速不敌网易云音乐的腾讯音乐,还有什么故事能说?

    5月底,国内领先的在线音乐平台网易云音乐正式递交招股书,于香港寻求上市.8月1日,据港交所文件,网易云音乐已通过港交所上市聆讯,正式向 "全球音乐社区第一股"发起冲击. 更新版招股 ...

最新文章

  1. 用产品思路建设中台,这走得通吗?| 白话中台
  2. mysql 连接查询_Swoole 实战:MySQL 查询器的实现(协程连接池)
  3. BlueCat 批量网站查询工具,全网最快的查询工具!!
  4. 游戏开发引擎 Cryengine 在 GitHub 上公开全部源代码
  5. MySQL WARN: Establishing SSL connection ...... is not recommended.
  6. c#委托和事件的介绍
  7. PHP 下载pdf预览和下载pdf文件
  8. MVPArms官方快速组件化方案开源,来自5K star的信赖
  9. 读程士宏《测度论和概率论基础》
  10. 【python爬虫】喜欢看小说又手头紧的小伙伴一定要看这篇文章,带你一步步制作一个小说下载器
  11. 植物突变体库(二)——EMS诱变
  12. Linux Shell 极简教程:一个例子
  13. 2020-12-01 剖析 Linux hypervisor
  14. 微信小程序(组件:路由、表单、媒体、自定义组件,插槽、组件通讯、侦听器、生命周期)
  15. JS如何改变元素内容?
  16. GNS3快捷安装指南
  17. C# 连接数据库,查询数据
  18. 百度api使用:文字识别(OCR)、长图文字识别、姓名识别
  19. React-简书项目
  20. Pycharm激活步骤

热门文章

  1. 智能手机、平板电脑与GPS定位精度
  2. Python+django+xadmin学习与开发笔记【04】快速开发后台管理系统
  3. KMeans 的使用
  4. 怎么让别人点击文字“加我为qq好友”就可以加你qq的网页链接
  5. 任正非:直到2006年我才抛弃自杀的念头
  6. php调用科大讯飞离线语音合成linux sdk
  7. 服务器怎么看u盘位置,安装服务器如何修改u盘地址
  8. [转载]数学各个研究方向简介
  9. Android距离感应器P-Sensor浅析
  10. SIP 请求方法(1)-INVITE