using Abp.Application.Services.Dto;
using Abp.Runtime.Caching;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Senparc.CO2NET.HttpUtility;
using Senparc.Weixin.CommonAPIs.ApiHandlerWapper;
using Senparc.Weixin.MP.Containers;
using Senparc.Weixin.MP.Entities;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks; namespace AbpProject.WeiXinMPCache
{
public class MPCacheAppService : AbpProjectAppServiceBase, IMPCacheAppService
{
/// <summary>
/// appid
/// </summary>
private readonly string AppIdSAddress = "WeiXinMP:AppID";
/// <summary>
/// appsecret
/// </summary>
private readonly string AppSecretAddress = "WeiXinMP:AppSecret";
/// <summary>
/// 获取token的路径
/// </summary>
private readonly string AccTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"; private readonly ICacheManager _cacheManager;
private readonly IConfiguration _appConfiguration; public MPCacheAppService(IConfiguration appConfiguration, ICacheManager cacheManager)
{
_appConfiguration = appConfiguration;
_cacheManager = cacheManager;
} /// <summary>
/// 获取公众微信号的token
/// </summary>
/// <returns></returns>
public async Task<string> GetAccessToken()
{
var acctoken = await _cacheManager.GetCache("WeiXinMP").GetOrDefaultAsync("AccessToken");
if (acctoken == null || string.IsNullOrEmpty(acctoken.ToString()))
{
var appId = _appConfiguration[AppIdSAddress];
var appSecret = _appConfiguration[AppSecretAddress];
var url = string.Format(AccTokenUrl, appId, appSecret);
var result = HttpClientHelper<AccessTokenResult>.Get(url,new AccessTokenResult());
if (result != null)
{
await _cacheManager.GetCache("WeiXinMP").SetAsync("AccessToken", result.access_token, TimeSpan.FromHours());
return result.access_token;
}
}
return acctoken.ToString();
} }
}

ABP 使用cache缓存的更多相关文章

  1. 缓存与ABP Redis Cache

    缓存与ABP Redis Cache 为什么要用缓存 为什么要用缓存呢,说缓存之前先说使用缓存的优点. 减少寄宿服务器的往返调用(round-trips). 如果缓存在客户端或是代理,将减少对服务器的 ...

  2. ABP理论学习之缓存Caching

    返回总目录 本篇目录 介绍 ICacheManager ICache ITypedCache 配置 介绍 ABP提供了缓存的抽象,它内部使用了这个缓存抽象.虽然默认的实现使用了MemoryCache, ...

  3. abp使用redis缓存

    利用NuGet程序包管理程序,添加 Abp.RedisCache 在 xxxx.Web.Core 项目的Module中注册Redis 在刚才上面这个类文件头部注册Redis组件 在Web.config ...

  4. 注释驱动的 Spring cache 缓存介绍

    概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...

  5. Windows Azure Cloud Service (43) 使用Azure In-Role Cache缓存(2)Dedicated Role

    <Windows Azure Platform 系列文章目录> Update 2016-01-12 https://azure.microsoft.com/zh-cn/documentat ...

  6. [转]注释驱动的 Spring cache 缓存介绍

    原文:http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ 概述 Spring 3.1 引入了激动人心的基于注释(an ...

  7. paip.cache 缓存架构以及性能提升总结

    paip.cache 缓存架构以及性能提升总结 1         缓存架构以及性能(贯穿读出式(LookThrough) 旁路读出式(LookAside) 写穿式(WriteThrough) 回写式 ...

  8. Cache缓存对象缓存对象

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoCache.aspx ...

  9. 注释驱动的 Spring cache 缓存介绍--转载

    概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...

随机推荐

  1. Shell 编程 文本处理工具 sed

    本篇主要写一些shell脚本文本处理工具sed的使用. 概述 sed(Stream EDitor)是一个强大而简单的文本解析转换工具,可以读取文本,并根据指定的条件对文本内容进行编辑(删除.替换.添加 ...

  2. 将qemu使用的设备树dump出来

    像下面的qemu启动命令: sudo qemu-system-aarch64 \ -M virt \ -cpu cortex-a53 \ -smp \ -m 4096M \ -kernel ./lin ...

  3. 批量部署SSH基于key的验证脚本

    工作中,使用ansible等自动化运维工具实现服务器批量自动化运维管理,需要先解决管理端和被管理端的免密码登录,可以脚本实现ssh基于key的验证,代码如下: #!/bin/bash PASS=123 ...

  4. 四步理解GloVe!(附代码实现)

    1. 说说GloVe 正如GloVe论文的标题而言,GloVe的全称叫Global Vectors for Word Representation,它是一个基于全局词频统计(count-based & ...

  5. 1 NLP学习大纲

    一.自然语言处理概述 1)自然语言处理:利用计算机为工具,对书面实行或者口头形式进行各种各样的处理和加工的技术,是研究人与人交际中以及人与计算机交际中的演员问题的一门学科,是人工智能的主要内容. 2) ...

  6. django 权限设置 左侧菜单点击显示,面包屑

    1.左侧菜单点击显示 就是在点击的时候保留点击的功能 方法. 1.加入新的字段,pid来判断 class Permission(models.Model): """ 权限 ...

  7. 《Exception团队》第三次作业:团队项目的原型设计

    一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 学习原型设计过程以及工具的使用 二.原型设计细 ...

  8. mysql在windows下安装(含客户端工具)

    下载 http://dev.mysql.com/downloads/ 安装 在出现选择安装类型的窗口中,有“typical(默认)”.“Complete(完全)”.“Custom(用户自定义)”三个选 ...

  9. wordcloud词云模块

    wordcloud词云模块 下载 pip install wordcloud 使用 import wordcloud##调用整个模块 form wordcloud import WordCloud## ...

  10. Mac 键盘符号说明

    Mac 键盘符号说明 ⌘ == Command ⇧ == Shift ⇪ == Caps Lock ⌥ == Option ⌃ == Control ↩ == Return/Enter ⌫ == De ...