当前位置: 首页 > news >正文

网站分站加盟小程序首页模板

网站分站加盟,小程序首页模板,上海招聘信息最新招聘,搜索引擎优化的工作流程是什么?一、背景说明 在已有的项目中,已经获取到了Graph的AccessToken并保存在内存里面。所以不希望再通过client secret或者certificate去创建GraphServiceClient对象。希望使用现有的token字符串来创建初始化创建GraphServiceClient从而来实现Graph其他API功能。 二、具体…
一、背景说明

在已有的项目中,已经获取到了Graph的AccessToken并保存在内存里面。所以不希望再通过client secret或者certificate去创建GraphServiceClient对象。希望使用现有的token字符串来创建初始化创建GraphServiceClient从而来实现Graph其他API功能。

二、具体实现

2.1 需要Java Graph SDK依赖 加入到pom.xml文件内

 <!-- Microsoft Graph SDK for Java --><dependency><groupId>com.microsoft.graph</groupId><artifactId>microsoft-graph</artifactId><version>[5.0,)</version></dependency><!-- Azure AD Authentication SDK for Java --><dependency><groupId>com.azure</groupId><artifactId>azure-identity</artifactId><version>[1.3,)</version></dependency>

2.2 代码片段

  public static GraphServiceClient initGraphServiceClient() {IAuthenticationProvider authProvider = new IAuthenticationProvider() {@Overridepublic CompletableFuture<String> getAuthorizationTokenAsync(URL requestUrl) {CompletableFuture<String> future = new CompletableFuture<>();future.complete(Your_AccessToken);return future;}};return GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();}
三、测试

下面代码是实现调用创建GraphServiceClient,调用graph api发送带附件的邮件。

	public static String sendMail() {try {String mfrom = "xxxx@outlook.com";String to = "xxxx@outlook.com";GraphServiceClient<Request> graphClient = initGraphServiceClient();Message message = new Message();message.subject = "Meet for lunch?";ItemBody body = new ItemBody();body.contentType = BodyType.TEXT;body.content = "The new cafeteria is open.";message.body = body;LinkedList<Recipient> toRecipientsList = new LinkedList<Recipient>();Recipient toRecipients = new Recipient();EmailAddress emailAddress = new EmailAddress();emailAddress.address = to;toRecipients.emailAddress = emailAddress;toRecipientsList.add(toRecipients);message.toRecipients = toRecipientsList;// 构建附件LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();FileAttachment attachments = new FileAttachment();attachments.name = "hello word.txt";attachments.oDataType = "#microsoft.graph.fileAttachment";attachments.contentType = "text/plain";attachments.contentBytes = Base64.getDecoder().decode("SGVsbG8gV29ybGQh");attachmentsList.add(attachments);AttachmentCollectionResponse attachmentCollectionResponse = new AttachmentCollectionResponse();attachmentCollectionResponse.value = attachmentsList;AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage(attachmentCollectionResponse, null);message.attachments = attachmentCollectionPage;// 以指定用户邮箱发送邮件graphClient.users(mfrom).sendMail(UserSendMailParameterSet.newBuilder().withMessage(message).withSaveToSentItems(true).build()).buildRequest().post();log.info("send email success");return "success";} catch (Exception e) {e.printStackTrace();log.error("send email error : {}", e.getMessage());return e.getMessage();}}

http://www.hyszgw.com/news/52470.html

相关文章:

  • 戈韦思网站建设小程序样式模板
  • 手机网站页面设计要求众筹的网络营销是什么
  • 免费网站建设网站有那些产品网络推广方案设计
  • 基于wap的企业网站设计与实现wordpress用的人多吗
  • 开源镜像网站开发学校网站怎么做优化
  • 滁州市城市建设投资有限公司网站张家港优化网站seo
  • 分类信息网站手机版云服务器拿来做网站
  • 单页营销型网站模板下载个人网站设计目的
  • 手机端网站建站手册学产品设计好找工作吗
  • 四平英文网站建设网站的备案在哪备案吗
  • 合肥网站建设哪家好招聘网页设计师
  • 网站建设销售需要懂的知识个人摄影网站源码
  • 合肥国际网站建设正规平台如何搭建一个个人网站
  • 网站运营编辑建设部的网站首页
  • 汕头建站程序毕设做购物网站
  • 电子政务与网站建设 总结企业网站分为哪三种类型
  • 网站效果信德 网站建设
  • 大连网站前端制作公司淘宝关键词排名怎么查
  • 潍坊 开发区网站建设软件开发工具的主要的分类方法
  • 公司建设网站的注意事项做网络推广常用网站
  • 企业网站建设问卷摄影类手机网站模板
  • wordpress主题 动漫seo值怎么提高
  • 网站打不开别人能打开布吉网站开发
  • dede打包好的网站怎么提取模板昌大建设总部哪里
  • 中山企业营销型网站制作潍坊高级网站建设价格
  • 百度提交网站已删内容沈阳网站开发工程师招聘网
  • 郑州网站建设兼职免费推广引流
  • 做网站费用需要分摊吗模板式网站
  • 智能建造考研方向南宁seo推广经验
  • 织梦网站选空间seo排名点击