├── .gitignore ├── Api.Core ├── Api.Core.csproj ├── Caching │ └── CacheManager.cs ├── Enums │ ├── MediaType.cs │ ├── MsgType.cs │ ├── ReceiveEventType.cs │ ├── ReceiveMessageType.cs │ └── ResponseMessageType.cs ├── Helpers │ ├── CryptoHelper.cs │ ├── CryptoRandom.cs │ ├── Cryptography.cs │ ├── HttpHelper.cs │ ├── JsonHelper.cs │ ├── SignHelper.cs │ ├── WXBizMsgCrypt.cs │ └── XmlHelper.cs ├── IJsonResult.cs ├── IRequest.cs ├── IXmlResult.cs ├── JsonResult.cs ├── Logging │ ├── ILogger.cs │ ├── ILoggerFactoryAdapter.cs │ ├── Log4Net │ │ ├── Log4NetLogger.cs │ │ └── Log4NetLoggerFactoryAdapter.cs │ ├── LogLevel.cs │ ├── LoggerExtension.cs │ ├── LoggerFactory.cs │ └── Null │ │ ├── NullLogger.cs │ │ └── NullLoggerFactoryAdapter.cs ├── Models │ ├── Article.cs │ ├── File.cs │ ├── Image.cs │ ├── LinkMessage.cs │ ├── MpArticle.cs │ ├── MpNews.cs │ ├── Music.cs │ ├── News.cs │ ├── OAMessage.cs │ ├── PostMedia.cs │ ├── Text.cs │ ├── Video.cs │ ├── Voice.cs │ └── wxcard.cs ├── Properties │ └── AssemblyInfo.cs ├── XmlModels │ ├── EncryptMessage.cs │ ├── IReceiveMessage.cs │ ├── IResponseMessage.cs │ ├── ReceiveMessageBase.cs │ ├── ReceiveMessageEventBase.cs │ ├── ReceiveMessageGeneralBase.cs │ ├── ReceiveMessageGenerals.cs │ ├── ReceiveMessagesEvents.cs │ └── ResponseMessage.cs └── packages.config ├── Api.Lanxin.Demo ├── Api.Lanxin.Demo.csproj ├── App_Start │ └── RouteConfig.cs ├── Global.asax ├── Global.asax.cs ├── Properties │ └── AssemblyInfo.cs ├── Views │ └── web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── packages.config ├── Api.Lanxin ├── Api.Lanxin.csproj ├── ApiHelper.cs ├── Enums │ └── MediaType.cs ├── Helpers │ ├── CryptoHelper.cs │ ├── CryptoRandom.cs │ ├── HttpHelper.cs │ ├── JsonHelper.cs │ ├── SignHelper.cs │ └── XmlHelper.cs ├── JsonResult.cs ├── Logging │ ├── ILogger.cs │ ├── ILoggerFactoryAdapter.cs │ ├── Log4Net │ │ ├── Log4NetLogger.cs │ │ └── Log4NetLoggerFactoryAdapter.cs │ ├── LogLevel.cs │ ├── LoggerExtension.cs │ ├── LoggerFactory.cs │ └── Null │ │ ├── NullLogger.cs │ │ └── NullLoggerFactoryAdapter.cs ├── Messages │ ├── ControlMessageResult.cs │ ├── GetAccessTokenResult.cs │ ├── GetMediaResult.cs │ ├── GetMemberResult.cs │ ├── GetParentStructResult.cs │ ├── GetSnsOAuthAccessTokenResult.cs │ ├── GetSnsUserInfoResult.cs │ ├── SendCustomMessageRequest.cs │ ├── SendMassMessageRequest.cs │ ├── SendMessageResult.cs │ ├── UploadMediaRequest.cs │ └── UploadMediaResult.cs ├── Models │ ├── MessageModels.cs │ └── PostMedia.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Api.Weixin.Demo ├── Api.Weixin.Demo.csproj ├── App_Data │ └── log4net.config ├── App_Start │ └── RouteConfig.cs ├── Content │ ├── Site.css │ ├── bootstrap.css │ └── bootstrap.min.css ├── Controllers │ ├── HomeController.cs │ └── WeixinController.cs ├── Global.asax ├── Global.asax.cs ├── MessageProcessors │ ├── Hanlders │ │ ├── IMessageHandler.cs │ │ ├── MpMessageHandler.cs │ │ └── QyMessageHandler.cs │ ├── IMessageProcessor.cs │ ├── MpMessageProcessor.cs │ └── ReceiveMessageProcessor.cs ├── Properties │ ├── AssemblyInfo.cs │ └── PublishProfiles │ │ └── release.pubxml ├── Scripts │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-1.10.2.intellisense.js │ ├── jquery-1.10.2.js │ ├── jquery-1.10.2.min.js │ ├── jquery-1.10.2.min.map │ └── modernizr-2.6.2.js ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Shared │ │ └── _Layout.cshtml │ ├── _ViewStart.cshtml │ └── web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff └── packages.config ├── Api.Weixin.Mp ├── Api.Weixin.Mp.csproj ├── ApiHelper.cs ├── Extensions │ ├── MpAPIHelperExtensions.cs │ └── MpTokenManagerExtensions.cs ├── Messages │ ├── AddTemplateResult.cs │ ├── CreateGroupResult.cs │ ├── GetAccessTokenResult.cs │ ├── GetCallbackIPResult.cs │ ├── GetGroupIdByOpenIdResult.cs │ ├── GetGroupListResult.cs │ ├── GetKFListResult.cs │ ├── GetMassMessageResult.cs │ ├── GetMediaResult.cs │ ├── GetSNSAccessTokenResult.cs │ ├── GetSNSUserInfoResult.cs │ ├── GetShortUrlResult.cs │ ├── GetUserInfoResult.cs │ ├── GetUserListResult.cs │ ├── SendKFMessageRequest.cs │ ├── SendMassMessageResult.cs │ ├── SendTemplateMessageRequest.cs │ ├── SendTemplateMessageResult.cs │ ├── UploadMediaNewsRequest.cs │ ├── UploadMediaNewsResult.cs │ ├── UploadMediaRequest.cs │ └── UploadMediaResult.cs ├── Models │ ├── Group.cs │ └── KFMessage.cs ├── Open │ ├── Messages │ │ ├── GetAuthorizerInfoResult.cs │ │ ├── GetAuthorizerOptionResult.cs │ │ ├── GetComponentAccessTokenResult.cs │ │ ├── GetComponentPreAuthCodeResult.cs │ │ ├── GetSNSAccessTokenResult.cs │ │ ├── GetUserInfoResult.cs │ │ ├── QueryComponentAuthResult.cs │ │ ├── RefreshAuthorizerTokenResult.cs │ │ ├── RefreshSNSAccessTokenResult.cs │ │ └── SetAuthorizerOptionResult.cs │ ├── Models │ │ └── funcscope_category.cs │ └── OpenHelperExtensions.cs ├── Properties │ └── AssemblyInfo.cs ├── TokenManager.cs └── packages.config ├── Api.Weixin.Pay ├── Api.Weixin.Pay.csproj ├── Config │ ├── DefaultWePayConfigAdapter.cs │ ├── IWePayConfigAdapter.cs │ └── WePayConfigFactory.cs ├── Fields │ ├── CloseOrderFields.cs │ ├── DownloadBillFields.cs │ ├── OrderQueryFields.cs │ ├── RefundFields.cs │ ├── RefundQueryFields.cs │ └── UnifiedOrderFields.cs ├── Messages │ ├── SignBaseReqest.cs │ └── UnifiedOrderRequest.cs ├── Models │ ├── WePayConfig.cs │ └── WePayData.cs ├── Properties │ └── AssemblyInfo.cs ├── WePayApi.cs └── WePayException.cs ├── Api.Weixin.Qy ├── Api.Weixin.Qy.csproj ├── ApiHelper.cs ├── Messages │ ├── AddTagMembersRequest.cs │ ├── AddTagMembersResult.cs │ ├── ConvertOpenIdToUserIdResult.cs │ ├── ConvertUserIdToOpenIdResult.cs │ ├── CreateChatRequest.cs │ ├── CreateDepartmentRequest.cs │ ├── CreateDepartmentResult.cs │ ├── CreateTagRequest.cs │ ├── CreateTagResult.cs │ ├── CreateUserRequest.cs │ ├── DeleteTagUsersResult.cs │ ├── GetAccessTokenResult.cs │ ├── GetAgentListResult.cs │ ├── GetAgentResult.cs │ ├── GetChatResult.cs │ ├── GetDepartmentResult.cs │ ├── GetJsapiTicketResult.cs │ ├── GetLoginInfoResult.cs │ ├── GetMediaResult.cs │ ├── GetProviderTokenRequest.cs │ ├── GetProviderTokenResult.cs │ ├── GetTagUserResult.cs │ ├── GetUserListResult.cs │ ├── GetUserResult.cs │ ├── GetUserSimpleListResult.cs │ ├── OAuthAuthorizeResult.cs │ ├── OAuthGetUserInfoResult.cs │ ├── SendChatRequest.cs │ ├── SendMessageRequest.cs │ ├── SendMessageResult.cs │ ├── SetAgentRequest.cs │ ├── SetMuteChatResult.cs │ ├── UpdateChatRequest.cs │ ├── UpdateTagRequest.cs │ ├── UpdateUserRequest.cs │ ├── UploadMediaRequest.cs │ └── UploadMediaResult.cs ├── Models │ ├── AgentInfo.cs │ ├── ChatInfo.cs │ ├── ChatReceiver.cs │ ├── Department.cs │ ├── SetMuteChatInfo.cs │ ├── UserExtensionAttribute.cs │ ├── UserExtensionAttributeItem.cs │ ├── UserInfo.cs │ └── UserSimple.cs ├── Properties │ └── AssemblyInfo.cs ├── ThirdAuth │ ├── Messages │ │ ├── GetAgentRequest.cs │ │ ├── GetAgentResult.cs │ │ ├── GetAuthInfoRequest.cs │ │ ├── GetAuthInfoResult.cs │ │ ├── GetCorpTokenRequest.cs │ │ ├── GetCorpTokenResult.cs │ │ ├── GetPermanentCodeRequest.cs │ │ ├── GetPermanentCodeResult.cs │ │ ├── GetPreAuthCodeReqeust.cs │ │ ├── GetPreAuthCodeResult.cs │ │ ├── GetSuiteTokenRequest.cs │ │ ├── GetSuiteTokenResult.cs │ │ ├── SetAgentRequest.cs │ │ ├── SetAgentResult.cs │ │ ├── SetSessionInfoRequest.cs │ │ └── SyncGetPageResult.cs │ ├── Models │ │ ├── AuthAgent.cs │ │ ├── AuthCorpInfo.cs │ │ ├── AuthDepartment.cs │ │ ├── AuthInfo.cs │ │ └── AuthUserInfo.cs │ ├── ThirdAuthApiHelperExtensions.cs │ └── ThirdAuthTokenManagerExtensions.cs ├── TokenManager.cs └── packages.config ├── LICENSE ├── README.md └── wechat_api.sln /.gitignore: -------------------------------------------------------------------------------- 1 | Thunbs.db 2 | .vs 3 | *.obj 4 | *.exe 5 | *.pdb 6 | *.user 7 | *.aps 8 | *.pch 9 | *.vspscc 10 | *_i.c 11 | *_p.c 12 | *.ncb 13 | *.suo 14 | *.tlb 15 | *.tlh 16 | *.bak 17 | *.cache 18 | *.ilk 19 | *.log 20 | [Bb]in 21 | [Dd]ebug*/ 22 | *.lib 23 | *.sbr 24 | obj/ 25 | [Rr]elease*/ 26 | _ReSharper*/ 27 | Api.Demo.ConsoleApp/ 28 | API.Demo/ 29 | packages/ 30 | API/ 31 | *.API/ 32 | A[P][I].*/ 33 | WechatAPI.sln 34 | Wechat.*/ 35 | API.Mp/ 36 | API.Qy/ 37 | Api.Weixin.Demo0/ 38 | -------------------------------------------------------------------------------- /Api.Core/Enums/MediaType.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Api.Core.Enums 5 | { 6 | /// 7 | /// 8 | /// 9 | public enum MediaType : int 10 | { 11 | /// 12 | /// 图片 13 | /// 14 | //[Display(Name = "image")] 15 | image = 0, 16 | /// 17 | /// 语音 18 | /// 19 | //[Display(Name = "voice")] 20 | voice = 1, 21 | /// 22 | /// 视频 23 | /// 24 | //[Display(Name = "video")] 25 | video = 2, 26 | /// 27 | /// 普通文件 28 | /// 29 | //[Display(Name = "file")] 30 | file = 3 31 | } 32 | } -------------------------------------------------------------------------------- /Api.Core/Enums/MsgType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Enums 7 | { 8 | /// 9 | /// 10 | /// 11 | public enum MsgType 12 | { 13 | /// 14 | /// 文本 15 | /// 16 | text, 17 | /// 18 | /// 图片 19 | /// 20 | image, 21 | /// 22 | /// 文件 23 | /// 24 | file, 25 | /// 26 | /// 录音 27 | /// 28 | voice, 29 | /// 30 | /// 音乐 31 | /// 32 | music, 33 | /// 34 | /// 卡 35 | /// 36 | wxcard, 37 | /// 38 | /// 文章 39 | /// 40 | article, 41 | /// 42 | /// 图文 43 | /// 44 | mparticle, 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Api.Core/Enums/ReceiveEventType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Api.Core.Enums 7 | { 8 | /// 9 | /// 事件类型 10 | /// 11 | public enum ReceiveEventType 12 | { 13 | /// 14 | /// 单击 15 | /// 16 | click = 0, 17 | /// 18 | /// 浏览 19 | /// 20 | view, 21 | /// 22 | /// 订阅 23 | /// 24 | subscribe, 25 | /// 26 | /// 取消订阅 27 | /// 28 | unsubscribe, 29 | /// 30 | /// 上报地理位置事件 31 | /// 32 | LOCATION, 33 | /// 34 | /// 扫码推事件 35 | /// 36 | scancode_push, 37 | /// 38 | /// 扫码推事件且弹出“消息接收中”提示框的事件推送 39 | /// 40 | scancode_waitmsg, 41 | /// 42 | /// 弹出系统拍照发图的事件推送 43 | /// 44 | pic_sysphoto, 45 | /// 46 | /// 弹出微信相册发图器的事件推送 47 | /// 48 | pic_photo_or_album, 49 | /// 50 | /// 弹出地理位置选择器的事件推送 51 | /// 52 | location_select, 53 | /// 54 | /// 群发消息推送完成事件推送 55 | /// 56 | MASSSENDJOBFINISH, 57 | /// 58 | /// 创建会话 59 | /// 60 | create_chat, 61 | /// 62 | /// 修改会话 63 | /// 64 | update_chat, 65 | /// 66 | /// 退出会话 67 | /// 68 | quit_chat, 69 | 70 | } 71 | } -------------------------------------------------------------------------------- /Api.Core/Enums/ReceiveMessageType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Api.Core.Enums 7 | { 8 | /// 9 | /// 接收消息类型枚举 10 | /// 11 | public enum ReceiveMessageType 12 | { 13 | /// 14 | /// 文本 15 | /// 16 | text = 0, 17 | /// 18 | /// 图片 19 | /// 20 | image = 1, 21 | /// 22 | /// 语音 23 | /// 24 | voice = 2, 25 | /// 26 | /// 视频 27 | /// 28 | video = 3, 29 | /// 30 | /// 地理位置 31 | /// 32 | location = 4, 33 | /// 34 | /// 事件 35 | /// 36 | @event = 5, 37 | /// 38 | /// 链接 39 | /// 40 | link = 6, 41 | } 42 | } -------------------------------------------------------------------------------- /Api.Core/Enums/ResponseMessageType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Enums 7 | { 8 | /// 9 | /// 响应消息类型,0=text,1=image,2=voice,3=video,4=news 10 | /// 11 | public enum ResponseMessageType 12 | { 13 | /// 14 | /// 文本消息 15 | /// 16 | text = 0, 17 | /// 18 | /// 图片消息 19 | /// 20 | image, 21 | /// 22 | /// 语音消息 23 | /// 24 | voice, 25 | /// 26 | /// 视频消息 27 | /// 28 | video, 29 | /// 30 | /// 图文消息 31 | /// 32 | news, 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Api.Core/Helpers/CryptoRandom.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | 7 | namespace Api.Core.Helpers 8 | { 9 | internal class CryptoRandom : RandomNumberGenerator 10 | { 11 | private static RandomNumberGenerator r; 12 | 13 | /// 14 | /// Creates an instance of the default implementation of a cryptographic random number generator that can be used to generate random data. 15 | /// 16 | public CryptoRandom() 17 | { 18 | r = RandomNumberGenerator.Create(); 19 | } 20 | 21 | /// 22 | /// Fills the elements of a specified array of bytes with random numbers. 23 | /// 24 | ///An array of bytes to contain random numbers. 25 | public override void GetBytes(byte[] buffer) 26 | { 27 | r.GetBytes(buffer); 28 | } 29 | 30 | /// 31 | /// Returns a random number between 0.0 and 1.0. 32 | /// 33 | public double NextDouble() 34 | { 35 | byte[] b = new byte[4]; 36 | r.GetBytes(b); 37 | return (double)BitConverter.ToUInt32(b, 0) / UInt32.MaxValue; 38 | } 39 | 40 | /// 41 | /// Returns a random number within the specified range. 42 | /// 43 | ///The inclusive lower bound of the random number returned. 44 | ///The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue. 45 | public int Next(int minValue, int maxValue) 46 | { 47 | return (int)Math.Round(NextDouble() * (maxValue - minValue - 1)) + minValue; 48 | } 49 | 50 | /// 51 | /// Returns a nonnegative random number. 52 | /// 53 | public int Next() 54 | { 55 | return Next(0, Int32.MaxValue); 56 | } 57 | 58 | /// 59 | /// Returns a nonnegative random number less than the specified maximum 60 | /// 61 | ///The inclusive upper bound of the random number returned. maxValue must be greater than or equal 0 62 | public int Next(int maxValue) 63 | { 64 | return Next(0, maxValue); 65 | } 66 | 67 | public override void GetNonZeroBytes(byte[] data) 68 | { 69 | r.GetNonZeroBytes(data); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Api.Core/Helpers/JsonHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Web.Script.Serialization; 8 | 9 | namespace Api.Core.Helpers 10 | { 11 | /// 12 | /// Json帮助类,用于将对象/JSON对象转换 13 | /// 14 | public class JsonHelper 15 | { 16 | /// 17 | /// unicode解码 18 | /// 19 | /// 20 | /// 21 | private static string DecodeUnicode(Match match) 22 | { 23 | if (!match.Success) 24 | return null; 25 | char outStr = (char)int.Parse(match.Value.Remove(0, 2), System.Globalization.NumberStyles.HexNumber); 26 | return new string(outStr, 1); 27 | } 28 | /// 29 | /// 将数据对象转换为 JavaScript 对象表示法 (JSON) 格式的字符串。 30 | /// 31 | /// 32 | /// 33 | public static string Encode(object obj) 34 | { 35 | JavaScriptSerializer serializer = new JavaScriptSerializer(); 36 | string encode = serializer.Serialize(obj); 37 | //解码Unicode,也可以通过设置App.Config(Web.Config)设置来做,这里只是暂时弥补一下,用到的地方不多 38 | MatchEvaluator evaluator = new MatchEvaluator(DecodeUnicode); 39 | //或:[\\u007f-\\uffff],\对应为\u000a,但一般情况下会保持 40 | var json = Regex.Replace(encode, @"\\u[0123456789abcdef]{4}", evaluator); 41 | return json; 42 | } 43 | /// 44 | /// 将 JavaScript 对象表示法 (JSON) 格式的数据转换为指定的强类型数据列表。 45 | /// 46 | /// 47 | /// 48 | /// 49 | public static T Decode(string input) where T : class 50 | { 51 | if (typeof(T) == typeof(string)) 52 | return input as T; 53 | 54 | JavaScriptSerializer serializer = new JavaScriptSerializer(); 55 | return serializer.Deserialize(input); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Api.Core/IJsonResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Api.Core 4 | { 5 | /// 6 | /// 7 | /// 8 | public interface IJsonResult 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Api.Core/IRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Api.Core 4 | { 5 | /// 6 | /// 7 | /// 8 | public interface IRequest 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Api.Core/IXmlResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Api.Core 4 | { 5 | /// 6 | /// 7 | /// 8 | public interface IXmlResult 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Api.Core/JsonResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Core 5 | { 6 | /// 7 | /// 8 | /// 9 | public class JsonResult : IJsonResult 10 | { 11 | /// 12 | /// 13 | /// 14 | public int errcode { get; set; } 15 | /// 16 | /// 17 | /// 18 | public string errmsg { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Api.Core/Logging/ILogger.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Api.Core.Logging 5 | { 6 | /// 7 | /// 系统日志接口(日志记录的API) 8 | /// 9 | public interface ILogger 10 | { 11 | /// 12 | /// 检查level级别的日志是否启用 13 | /// 14 | /// 日志级别 15 | /// 如果启用返回true,否则返回false 16 | bool IsEnabled(LogLevel level); 17 | /// 18 | /// 记录level级别的日志 19 | /// 20 | /// 日志级别 21 | /// 需记录的内容 22 | void Log(LogLevel level, object message); 23 | /// 24 | /// 记录level级别的日志 25 | /// 26 | /// 日志级别 27 | /// 异常 28 | /// 需记录的内容 29 | void Log(LogLevel level, Exception exception, object message); 30 | /// 31 | /// 记录level级别的日志 32 | /// 33 | /// 日志级别 34 | /// 需记录的内容格式 35 | /// 替换format占位符的参数 36 | void Log(LogLevel level, string format, params object[] args); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Api.Core/Logging/ILoggerFactoryAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Logging 7 | { 8 | /// 9 | /// 供LoggerFactory使用的适配器接口,适配器用户配置日志记录工具的各项参数 10 | /// 11 | public interface ILoggerFactoryAdapter 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | ILogger GetLogger(string loggerName); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Api.Core/Logging/Log4Net/Log4NetLoggerFactoryAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using log4net; 4 | using log4net.Config; 5 | using Api.Core.Helpers; 6 | 7 | namespace Api.Core.Logging.Log4Net 8 | { 9 | /// 10 | /// 用log4net实现的LoggerFactoryAdapter 11 | /// 12 | public class Log4NetLoggerFactoryAdapter : ILoggerFactoryAdapter 13 | { 14 | private static bool IsConfigured; 15 | private static ILogger logger; 16 | 17 | static Log4NetLoggerFactoryAdapter() 18 | { 19 | } 20 | 21 | /// 22 | /// 构造函数(默认加载"~/Config/log4net.config"作为log4net配置文件) 23 | /// 24 | public Log4NetLoggerFactoryAdapter() 25 | : this("~/app_data/log4net.config") 26 | { 27 | 28 | } 29 | /// 30 | /// 构造函数 31 | /// 32 | /// 33 | /// 34 | /// log4net配置文件路径,支持以下格式: 35 | /// 36 | /// ~/config/log4net.config 37 | /// ~/web.config 38 | /// c:\abc\log4net.config 39 | /// 40 | /// 41 | /// 42 | public Log4NetLoggerFactoryAdapter(string configFilename) 43 | { 44 | if (Log4NetLoggerFactoryAdapter.IsConfigured) 45 | return; 46 | //IRunningEnvironment runningEnvironment = DIContainer.Resolve(); 47 | if (string.IsNullOrEmpty(configFilename)) 48 | configFilename = "~/app_data/log4net.config"; 49 | //FileInfo fileInfo = new FileInfo(WebUtility.GetPhysicalFilePath(configFilename)); 50 | FileInfo fileInfo = new FileInfo(configFilename); 51 | if (!fileInfo.Exists) 52 | throw new ApplicationException(string.Format("log4net配置文件 {0} 未找到", fileInfo.FullName)); 53 | //if (runningEnvironment.IsFullTrust) 54 | // XmlConfigurator.ConfigureAndWatch(fileInfo); 55 | //else 56 | //{ 57 | XmlConfigurator.Configure(fileInfo); 58 | Log4NetLoggerFactoryAdapter.IsConfigured = true; 59 | //} 60 | } 61 | 62 | /// 63 | /// 依据LoggerName获取 64 | /// 65 | /// 日志名称(例如:log4net的logger配置名称) 66 | /// 67 | public ILogger GetLogger(string loggerName) 68 | { 69 | if (logger == null) 70 | { 71 | logger = (ILogger)new Log4NetLogger(LogManager.GetLogger(loggerName)); 72 | } 73 | return logger; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Api.Core/Logging/LogLevel.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Api.Core.Logging 5 | { 6 | /// 7 | /// 8 | /// 9 | public enum LogLevel 10 | { 11 | /// 12 | /// 调试 13 | /// 14 | Debug, 15 | /// 16 | /// 信息 17 | /// 18 | Information, 19 | /// 20 | /// 警告 21 | /// 22 | Warning, 23 | /// 24 | /// 错误 25 | /// 26 | Error, 27 | /// 28 | /// 致命的 29 | /// 30 | Fatal 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Api.Core/Logging/LoggerFactory.cs: -------------------------------------------------------------------------------- 1 |  2 | using Api.Core.Logging.Null; 3 | 4 | namespace Api.Core.Logging 5 | { 6 | /// 7 | /// 8 | /// 9 | public static class LoggerFactory 10 | { 11 | private static ILoggerFactoryAdapter _loggerFactoryAdapter; 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static void InitializeLogFactory(ILoggerFactoryAdapter loggerFactoryAdapter) 17 | { 18 | _loggerFactoryAdapter = loggerFactoryAdapter; 19 | } 20 | 21 | /// 22 | /// 获取logger name为tunynet的 23 | /// 24 | /// 25 | public static ILogger GetLogger() 26 | { 27 | return LoggerFactory.GetLogger("logger"); 28 | } 29 | 30 | /// 31 | /// 依据LoggerName获取 32 | /// 33 | /// 日志名称(例如:log4net的logger配置名称) 34 | /// 35 | public static ILogger GetLogger(string loggerName) 36 | { 37 | if (_loggerFactoryAdapter == null) 38 | _loggerFactoryAdapter = new NullLoggerFactoryAdapter(); 39 | return _loggerFactoryAdapter.GetLogger(loggerName); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Api.Core/Logging/Null/NullLogger.cs: -------------------------------------------------------------------------------- 1 | using log4net; 2 | using System; 3 | 4 | namespace Api.Core.Logging.Null 5 | { 6 | /// 7 | /// 8 | /// 9 | public class NullLogger : ILogger 10 | { 11 | //private ILog _logger; 12 | 13 | internal NullLogger() 14 | { 15 | //_logger = log; 16 | } 17 | 18 | /// 19 | /// 20 | /// 21 | /// 22 | /// 23 | public bool IsEnabled(LogLevel level) 24 | { 25 | return false; 26 | } 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | public void Log(LogLevel level, object message) 33 | { } 34 | /// 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// 40 | public void Log(LogLevel level, Exception exception, object message) 41 | { } 42 | /// 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | public void Log(LogLevel level, string format, params object[] args) 49 | { } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Api.Core/Logging/Null/NullLoggerFactoryAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using log4net; 4 | using log4net.Config; 5 | using Api.Core.Helpers; 6 | 7 | namespace Api.Core.Logging.Null 8 | { 9 | /// 10 | /// 用log4net实现的LoggerFactoryAdapter 11 | /// 12 | public class NullLoggerFactoryAdapter : ILoggerFactoryAdapter 13 | { 14 | //private static bool IsConfigured; 15 | private static ILogger logger; 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | public ILogger GetLogger(string loggerName) 22 | { 23 | if (logger == null) 24 | { 25 | logger = (ILogger)new NullLogger(); 26 | } 27 | return logger; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Api.Core/Models/Article.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class Article 12 | { 13 | /// 14 | /// 标题 15 | /// 16 | public string title { get; set; } 17 | /// 18 | /// 描述 19 | /// 20 | public string description { get; set; } 21 | /// 22 | /// 点击后跳转的链接 23 | /// 24 | public string url { get; set; } 25 | /// 26 | /// 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80。如不填,在客户端不显示图片 27 | /// 28 | public string picurl { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Api.Core/Models/File.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class File 12 | {/// 13 | /// 14 | /// 15 | public string media_id { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Api.Core/Models/Image.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class Image 12 | {/// 13 | /// 14 | /// 15 | public string media_id { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Api.Core/Models/LinkMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// link消息 钉钉特有 10 | /// 11 | public class LinkMessage 12 | { 13 | /// 14 | /// 消息点击链接地址 15 | /// 16 | public string messageUrl { get; set; } 17 | /// 18 | /// 图片媒体文件id,可以调用上传媒体文件接口获取 19 | /// 20 | public string picUrl { get; set; } 21 | /// 22 | /// 消息标题 23 | /// 24 | public string title { get; set; } 25 | /// 26 | /// 消息描述 27 | /// 28 | public string text { get; set; } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Api.Core/Models/MpArticle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 图文文章 10 | /// 11 | public class MpArticle 12 | { 13 | /// 14 | /// 标题 15 | /// 16 | public string title { get; set; } 17 | /// 18 | /// 图文消息缩略图的media_id, 19 | /// 20 | public string thumb_media_id { get; set; } 21 | /// 22 | /// 图文消息的作者 23 | /// 24 | public string author { get; set; } 25 | /// 26 | /// 图文消息点击“阅读原文”之后的页面链接 27 | /// 28 | public string content_source_url { get; set; } 29 | /// 30 | /// 图文消息的内容,支持html标签 31 | /// 32 | public string content { get; set; } 33 | /// 34 | /// 图文消息的描述 35 | /// 36 | public string digest { get; set; } 37 | /// 38 | /// 是否显示封面,1为显示,0为不显示 39 | /// 40 | public int show_cover_pic { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Api.Core/Models/MpNews.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 用于发送图文文章消息 10 | /// 11 | public class MpNews 12 | { 13 | /// 14 | /// 15 | /// 16 | public MpNews() 17 | { } 18 | 19 | /// 20 | /// 图文消息,一个图文消息支持1到10个图文 21 | /// 22 | public IList articles { get; set; } 23 | 24 | /// 25 | /// 26 | /// 27 | public string media_id { get; set; } 28 | 29 | /// 30 | /// 31 | /// 32 | /// 33 | public void Add(MpArticle article) 34 | { 35 | if (articles == null) 36 | articles = new List(); 37 | articles.Add(article); 38 | } 39 | /// 40 | /// 41 | /// 42 | /// 43 | public void SetMediaId(string mediaId) 44 | { 45 | this.media_id = mediaId; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Api.Core/Models/Music.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class Music 12 | { 13 | /// 14 | /// 15 | /// 16 | public string title { get; set; } 17 | /// 18 | /// 19 | /// 20 | public string description { get; set; } 21 | /// 22 | /// 23 | /// 24 | public string musicurl { get; set; } 25 | /// 26 | /// 27 | /// 28 | public string hqmusicurl { get; set; } 29 | /// 30 | /// 31 | /// 32 | public string thumb_media_id { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Api.Core/Models/News.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class News 12 | { 13 | /// 14 | /// 15 | /// 16 | public IList
articles { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Api.Core/Models/PostMedia.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Core.Models 8 | { 9 | /// 10 | /// 用于上传的媒体 11 | /// 12 | public class PostMedia 13 | { 14 | private Byte[] _byteData; 15 | /// 16 | /// 17 | /// 18 | public PostMedia() 19 | { 20 | 21 | } 22 | /// 23 | /// 文件名称 24 | /// 25 | public string Name { get; set; } 26 | /// 27 | /// 文件名称,包含路径 28 | /// 29 | public string FullName { get; set; } 30 | ///// 31 | ///// 内容类型 32 | ///// 33 | //public string ContentType { get; set; } 34 | ///// 35 | ///// 内容大小 36 | ///// 37 | //public int ContentLength { get; set; } 38 | /// 39 | /// 文件流 40 | /// 41 | public Byte[] ByteData 42 | { 43 | get { return _byteData; } 44 | set { _byteData = value; } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Api.Core/Models/Text.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class Text 12 | {/// 13 | /// 14 | /// 15 | public string content { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Api.Core/Models/Video.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class Video 12 | { 13 | /// 14 | /// 15 | /// 16 | public string media_id { get; set; } 17 | /// 18 | /// 19 | /// 20 | public string thumb_media_id { get; set; } 21 | /// 22 | /// 23 | /// 24 | public string title { get; set; } 25 | /// 26 | /// 27 | /// 28 | public string description { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Api.Core/Models/Voice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class Voice 12 | {/// 13 | /// 14 | /// 15 | public string media_id { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Api.Core/Models/wxcard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class wxcard 12 | { 13 | 14 | /// 15 | /// 16 | /// 17 | public string card_id { get; set; } 18 | /// 19 | /// 20 | /// 21 | public string card_ext { get; set; } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Core")] 9 | [assembly: AssemblyDescription("微信API核心文件")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Core")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("8a094f62-0fb2-4040-aa9a-f5d5d825cafa")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.1.0.0")] 36 | [assembly: AssemblyFileVersion("1.1.0.0")] 37 | -------------------------------------------------------------------------------- /Api.Core/XmlModels/EncryptMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace Api.Core.XmlModels 8 | { 9 | /// 10 | /// 用于接收微信post过来的加密xml 11 | /// 12 | [XmlRoot("xml")] 13 | public class EncryptMessage 14 | { 15 | //private string agentId; 16 | 17 | /// 18 | /// 企业号CorpID 19 | /// 20 | public string ToUserName { get; set; } 21 | /// 22 | /// 消息密文 23 | /// 24 | public string Encrypt { get; set; } 25 | /// 26 | /// 应用ID 27 | /// 28 | public string AgentID { get; set; } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Api.Core/XmlModels/IReceiveMessage.cs: -------------------------------------------------------------------------------- 1 | using Api.Core.Enums; 2 | 3 | namespace Api.Core.XmlModels 4 | { 5 | /// 6 | /// 消息接收接口标识 7 | /// 8 | public interface IReceiveMessage 9 | { 10 | /// 11 | /// 接收者ID 12 | /// 13 | string ToUserName { get; set; } 14 | /// 15 | /// 发送者ID 16 | /// 17 | string FromUserName { get; set; } 18 | /// 19 | /// 消息创建时间(整型) 20 | /// 21 | double CreateTime { get; set; } 22 | /// 23 | /// 消息类型 24 | /// 25 | ReceiveMessageType MsgType { get; set; } 26 | ///// 27 | ///// 消息id,64位整型 28 | ///// 29 | //long MsgId { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Api.Core/XmlModels/IResponseMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Api.Core.Helpers; 6 | 7 | namespace Api.Core.XmlModels 8 | { 9 | /// 10 | /// 响应消息接口标识 11 | /// 12 | public interface IResponseMessage 13 | { 14 | /// 15 | /// 接收人 16 | /// 17 | string ToUserName { get; set; } 18 | /// 19 | /// 发起人 20 | /// 21 | string FromUserName { get; set; } 22 | /// 23 | /// 24 | /// 25 | int CreateTime { get; set; } 26 | /// 27 | /// 28 | /// 29 | string Content { get; set; } 30 | /// 31 | /// 转成xml对象 32 | /// 33 | /// 34 | string AsXmlString(); 35 | /// 36 | /// 加密消息 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | int EncryptMessage(WXBizMsgCrypt wxcpt, string token, out string encryptMsg); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Api.Core/XmlModels/ReceiveMessageEventBase.cs: -------------------------------------------------------------------------------- 1 |  2 | using Api.Core.Enums; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Xml.Serialization; 8 | 9 | namespace Api.Core.XmlModels 10 | { 11 | /// 12 | /// 事件消息基础类 13 | /// 14 | [XmlRoot("xml")] 15 | public class ReceiveMessageEventBase : ReceiveMessageBase 16 | { 17 | /// 18 | /// 消息类型 19 | /// 20 | public override ReceiveMessageType MsgType { get { return ReceiveMessageType.@event; } } 21 | /// 22 | /// 事件类型 23 | /// 24 | public string Event { get; set; } 25 | 26 | /// 27 | /// 获取事件类型 28 | /// 29 | /// 30 | public ReceiveEventType GetEventType() 31 | { 32 | var eventType = Event.ToLower(); 33 | ReceiveEventType tempEventType; 34 | Enum.TryParse(eventType, out tempEventType); 35 | return tempEventType; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Api.Core/XmlModels/ReceiveMessageGeneralBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Core.XmlModels 7 | { 8 | /// 9 | /// 接收普通消息基础类 10 | /// 11 | public class ReceiveMessageGeneralBase : ReceiveMessageBase 12 | { 13 | /// 14 | /// 消息ID 15 | /// 16 | public string MsgId { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Api.Core/XmlModels/ReceiveMessageGenerals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace Api.Core.XmlModels 8 | { 9 | /// 10 | /// 接收普通消息之图片消息 11 | /// 12 | [XmlRoot("xml")] 13 | public class ReceiveMessageText : ReceiveMessageGeneralBase 14 | { 15 | /// 16 | /// 消息内容 17 | /// 18 | public string Content { get; set; } 19 | } 20 | 21 | /// 22 | /// 接收普通消息之图片消息 23 | /// 24 | [XmlRoot("xml")] 25 | public class ReceiveMessageImage : ReceiveMessageGeneralBase 26 | { 27 | /// 28 | /// 图片链接,仅当MsgType为image类型时有效 29 | /// 30 | public string PicUrl { get; set; } 31 | /// 32 | /// 视频消息媒体id,可以调用多媒体文件下载接口拉取数据 33 | /// 34 | public string MediaId { get; set; } 35 | } 36 | 37 | /// 38 | /// 接收普通消息之语音消息 39 | /// 40 | [XmlRoot("xml")] 41 | public class ReceiveMessageVoice : ReceiveMessageGeneralBase 42 | { 43 | /// 44 | /// 视频消息媒体id,可以调用多媒体文件下载接口拉取数据 45 | /// 46 | public string MediaId { get; set; } 47 | /// 48 | /// 语音格式,如amr,speex等,仅MsgType当为voice时有效 49 | /// 50 | public string Format { get; set; } 51 | } 52 | 53 | /// 54 | /// 接收普通消息之视频消息 55 | /// 56 | [XmlRoot("xml")] 57 | public class ReceiveMessageVideo : ReceiveMessageGeneralBase 58 | { 59 | /// 60 | /// 视频消息媒体id,可以调用多媒体文件下载接口拉取数据 61 | /// 62 | public string MediaId { get; set; } 63 | /// 64 | /// 仅当为video时有效,视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据 65 | /// 66 | public string ThumbMediaId { get; set; } 67 | } 68 | 69 | /// 70 | /// 接收普通消息之位置消息 71 | /// 72 | [XmlRoot("xml")] 73 | public class ReceiveMessageLocation : ReceiveMessageGeneralBase 74 | { 75 | /// 76 | /// 地理位置纬度,仅当为location时有效 77 | /// 78 | public double Location_X { get; set; } 79 | /// 80 | /// 地理位置经度,仅当MsgType为location时有效 81 | /// 82 | public double Location_Y { get; set; } 83 | /// 84 | /// 地图缩放大小,仅当MsgType为location时有效 85 | /// 86 | public double Scale { get; set; } 87 | /// 88 | /// 地理位置信息,仅当MsgType为location时有效 89 | /// 90 | public string Label { get; set; } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Api.Core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace Api.Lanxin.Demo 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="Api.Lanxin.Demo.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace Api.Lanxin.Demo 9 | { 10 | public class MvcApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | AreaRegistration.RegisterAllAreas(); 15 | RouteConfig.RegisterRoutes(RouteTable.Routes); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Lanxin.Demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Lanxin.Demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("1ba9705d-1022-4c69-b79d-9ed2818e3e8f")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Views/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Api.Lanxin.Demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Api.Lanxin/Enums/MediaType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Api.Lanxin.Enums 7 | { 8 | /// 9 | /// 10 | /// 11 | public enum MediaType 12 | { 13 | /// 14 | /// 图片 15 | /// 16 | //[Display(Name = "image")] 17 | image = 0, 18 | /// 19 | /// 语音 20 | /// 21 | //[Display(Name = "voice")] 22 | voice = 1, 23 | /// 24 | /// 视频 25 | /// 26 | //[Display(Name = "video")] 27 | video = 2, 28 | /// 29 | /// 普通文件 30 | /// 31 | //[Display(Name = "file")] 32 | file = 3 33 | } 34 | } -------------------------------------------------------------------------------- /Api.Lanxin/Helpers/CryptoRandom.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | 7 | namespace Api.Lanxin.Helpers 8 | { 9 | internal class CryptoRandom : RandomNumberGenerator 10 | { 11 | private static RandomNumberGenerator r; 12 | 13 | /// 14 | /// Creates an instance of the default implementation of a cryptographic random number generator that can be used to generate random data. 15 | /// 16 | public CryptoRandom() 17 | { 18 | r = RandomNumberGenerator.Create(); 19 | } 20 | 21 | /// 22 | /// Fills the elements of a specified array of bytes with random numbers. 23 | /// 24 | ///An array of bytes to contain random numbers. 25 | public override void GetBytes(byte[] buffer) 26 | { 27 | r.GetBytes(buffer); 28 | } 29 | 30 | /// 31 | /// Returns a random number between 0.0 and 1.0. 32 | /// 33 | public double NextDouble() 34 | { 35 | byte[] b = new byte[4]; 36 | r.GetBytes(b); 37 | return (double)BitConverter.ToUInt32(b, 0) / UInt32.MaxValue; 38 | } 39 | 40 | /// 41 | /// Returns a random number within the specified range. 42 | /// 43 | ///The inclusive lower bound of the random number returned. 44 | ///The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue. 45 | public int Next(int minValue, int maxValue) 46 | { 47 | return (int)Math.Round(NextDouble() * (maxValue - minValue - 1)) + minValue; 48 | } 49 | 50 | /// 51 | /// Returns a nonnegative random number. 52 | /// 53 | public int Next() 54 | { 55 | return Next(0, Int32.MaxValue); 56 | } 57 | 58 | /// 59 | /// Returns a nonnegative random number less than the specified maximum 60 | /// 61 | ///The inclusive upper bound of the random number returned. maxValue must be greater than or equal 0 62 | public int Next(int maxValue) 63 | { 64 | return Next(0, maxValue); 65 | } 66 | 67 | public override void GetNonZeroBytes(byte[] data) 68 | { 69 | r.GetNonZeroBytes(data); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Api.Lanxin/Helpers/JsonHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Web.Script.Serialization; 8 | 9 | namespace Api.Lanxin.Helpers 10 | { 11 | /// 12 | /// Json帮助类,用于将对象/JSON对象转换 13 | /// 14 | public class JsonHelper 15 | { 16 | /// 17 | /// unicode解码 18 | /// 19 | /// 20 | /// 21 | private static string DecodeUnicode(Match match) 22 | { 23 | if (!match.Success) 24 | return null; 25 | char outStr = (char)int.Parse(match.Value.Remove(0, 2), System.Globalization.NumberStyles.HexNumber); 26 | return new string(outStr, 1); 27 | } 28 | /// 29 | /// 将数据对象转换为 JavaScript 对象表示法 (JSON) 格式的字符串。 30 | /// 31 | /// 32 | /// 33 | public static string Encode(object obj) 34 | { 35 | JavaScriptSerializer serializer = new JavaScriptSerializer(); 36 | string encode = serializer.Serialize(obj); 37 | //解码Unicode,也可以通过设置App.Config(Web.Config)设置来做,这里只是暂时弥补一下,用到的地方不多 38 | MatchEvaluator evaluator = new MatchEvaluator(DecodeUnicode); 39 | //或:[\\u007f-\\uffff],\对应为\u000a,但一般情况下会保持 40 | var json = Regex.Replace(encode, @"\\u[0123456789abcdef]{4}", evaluator); 41 | return json; 42 | } 43 | /// 44 | /// 将 JavaScript 对象表示法 (JSON) 格式的数据转换为指定的强类型数据列表。 45 | /// 46 | /// 47 | /// 48 | /// 49 | public static T Decode(string input) where T : class 50 | { 51 | if (typeof(T) == typeof(string)) 52 | return input as T; 53 | 54 | JavaScriptSerializer serializer = new JavaScriptSerializer(); 55 | return serializer.Deserialize(input); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Api.Lanxin/JsonResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin 8 | { 9 | /// 10 | /// 11 | /// 12 | public class JsonResult 13 | { 14 | /// 15 | /// 错误代码 16 | /// 17 | public int errcode { get; set; } 18 | /// 19 | /// 错误信息 20 | /// 21 | public string errmsg { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/ILogger.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Api.Lanxin.Logging 5 | { 6 | /// 7 | /// 系统日志接口(日志记录的API) 8 | /// 9 | public interface ILogger 10 | { 11 | /// 12 | /// 检查level级别的日志是否启用 13 | /// 14 | /// 日志级别 15 | /// 如果启用返回true,否则返回false 16 | bool IsEnabled(LogLevel level); 17 | /// 18 | /// 记录level级别的日志 19 | /// 20 | /// 日志级别 21 | /// 需记录的内容 22 | void Log(LogLevel level, object message); 23 | /// 24 | /// 记录level级别的日志 25 | /// 26 | /// 日志级别 27 | /// 异常 28 | /// 需记录的内容 29 | void Log(LogLevel level, Exception exception, object message); 30 | /// 31 | /// 记录level级别的日志 32 | /// 33 | /// 日志级别 34 | /// 需记录的内容格式 35 | /// 替换format占位符的参数 36 | void Log(LogLevel level, string format, params object[] args); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/ILoggerFactoryAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Lanxin.Logging 7 | { 8 | /// 9 | /// 供LoggerFactory使用的适配器接口,适配器用户配置日志记录工具的各项参数 10 | /// 11 | public interface ILoggerFactoryAdapter 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | ILogger GetLogger(string loggerName); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/Log4Net/Log4NetLoggerFactoryAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using log4net; 4 | using log4net.Config; 5 | 6 | 7 | namespace Api.Lanxin.Logging.Log4Net 8 | { 9 | /// 10 | /// 用log4net实现的LoggerFactoryAdapter 11 | /// 12 | public class Log4NetLoggerFactoryAdapter : ILoggerFactoryAdapter 13 | { 14 | private static bool IsConfigured; 15 | private static ILogger logger; 16 | 17 | static Log4NetLoggerFactoryAdapter() 18 | { 19 | } 20 | 21 | /// 22 | /// 构造函数(默认加载"~/Config/log4net.config"作为log4net配置文件) 23 | /// 24 | public Log4NetLoggerFactoryAdapter() 25 | : this("~/app_data/log4net.config") 26 | { 27 | 28 | } 29 | /// 30 | /// 构造函数 31 | /// 32 | /// 33 | /// 34 | /// log4net配置文件路径,支持以下格式: 35 | /// 36 | /// ~/config/log4net.config 37 | /// ~/web.config 38 | /// c:\abc\log4net.config 39 | /// 40 | /// 41 | /// 42 | public Log4NetLoggerFactoryAdapter(string configFilename) 43 | { 44 | if (Log4NetLoggerFactoryAdapter.IsConfigured) 45 | return; 46 | //IRunningEnvironment runningEnvironment = DIContainer.Resolve(); 47 | if (string.IsNullOrEmpty(configFilename)) 48 | configFilename = "~/app_data/log4net.config"; 49 | //FileInfo fileInfo = new FileInfo(WebUtility.GetPhysicalFilePath(configFilename)); 50 | FileInfo fileInfo = new FileInfo(configFilename); 51 | if (!fileInfo.Exists) 52 | throw new ApplicationException(string.Format("log4net配置文件 {0} 未找到", fileInfo.FullName)); 53 | //if (runningEnvironment.IsFullTrust) 54 | // XmlConfigurator.ConfigureAndWatch(fileInfo); 55 | //else 56 | //{ 57 | XmlConfigurator.Configure(fileInfo); 58 | Log4NetLoggerFactoryAdapter.IsConfigured = true; 59 | //} 60 | } 61 | 62 | /// 63 | /// 依据LoggerName获取 64 | /// 65 | /// 日志名称(例如:log4net的logger配置名称) 66 | /// 67 | public ILogger GetLogger(string loggerName) 68 | { 69 | if (logger == null) 70 | { 71 | logger = (ILogger)new Log4NetLogger(LogManager.GetLogger(loggerName)); 72 | } 73 | return logger; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/LogLevel.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Api.Lanxin.Logging 5 | { 6 | /// 7 | /// 8 | /// 9 | public enum LogLevel 10 | { 11 | /// 12 | /// 调试 13 | /// 14 | Debug, 15 | /// 16 | /// 信息 17 | /// 18 | Information, 19 | /// 20 | /// 警告 21 | /// 22 | Warning, 23 | /// 24 | /// 错误 25 | /// 26 | Error, 27 | /// 28 | /// 致命的 29 | /// 30 | Fatal 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/LoggerFactory.cs: -------------------------------------------------------------------------------- 1 |  2 | using Api.Lanxin.Logging.Null; 3 | 4 | namespace Api.Lanxin.Logging 5 | { 6 | /// 7 | /// 8 | /// 9 | public static class LoggerFactory 10 | { 11 | private static ILoggerFactoryAdapter _loggerFactoryAdapter; 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static void InitializeLogFactory(ILoggerFactoryAdapter loggerFactoryAdapter) 17 | { 18 | _loggerFactoryAdapter = loggerFactoryAdapter; 19 | } 20 | 21 | /// 22 | /// 获取logger 23 | /// 24 | /// / 25 | public static ILogger GetLogger() 26 | { 27 | return LoggerFactory.GetLogger("logger"); 28 | } 29 | 30 | /// 31 | /// 依据LoggerName获取 32 | /// 33 | /// 日志名称(例如:log4net的logger配置名称) 34 | /// / 35 | public static ILogger GetLogger(string loggerName) 36 | { 37 | if (_loggerFactoryAdapter == null) 38 | _loggerFactoryAdapter = new NullLoggerFactoryAdapter(); 39 | return _loggerFactoryAdapter.GetLogger(loggerName); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/Null/NullLogger.cs: -------------------------------------------------------------------------------- 1 | using log4net; 2 | using System; 3 | 4 | namespace Api.Lanxin.Logging.Null 5 | { 6 | /// 7 | /// 8 | /// 9 | public class NullLogger : ILogger 10 | { 11 | //private ILog _logger; 12 | /// 13 | /// 14 | /// 15 | internal NullLogger() 16 | { 17 | //_logger = log; 18 | } 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | public bool IsEnabled(LogLevel level) 25 | { 26 | return false; 27 | } 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | public void Log(LogLevel level, object message) 34 | { } 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | public void Log(LogLevel level, Exception exception, object message) 42 | { } 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | public void Log(LogLevel level, string format, params object[] args) 50 | { } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Api.Lanxin/Logging/Null/NullLoggerFactoryAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using log4net; 4 | using log4net.Config; 5 | 6 | namespace Api.Lanxin.Logging.Null 7 | { 8 | /// 9 | /// 用log4net实现的LoggerFactoryAdapter 10 | /// 11 | public class NullLoggerFactoryAdapter : ILoggerFactoryAdapter 12 | { 13 | //private static bool IsConfigured; 14 | private static ILogger logger; 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | public ILogger GetLogger(string loggerName) 21 | { 22 | if (logger == null) 23 | { 24 | logger = (ILogger)new NullLogger(); 25 | } 26 | return logger; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/ControlMessageResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// 查询消息送达、已读状态 11 | /// 12 | public class ControlMessageResult : JsonResult 13 | { 14 | public IList msgSendStateList { get; set; } 15 | } 16 | 17 | /// 18 | /// 查询消息状态信息 19 | /// 20 | public class MsgSendStateInfo 21 | { 22 | /// 23 | /// 24 | /// 25 | public int id { get; set; } 26 | /// 27 | /// 发送状态 28 | /// 29 | public int sendingState { get; set; } 30 | /// 31 | /// 手机号 32 | /// 33 | public int mobile { get; set; } 34 | /// 35 | /// Appid 36 | /// 37 | public int dialogId { get; set; } 38 | /// 39 | /// 发送时间 40 | /// 41 | public long sendTime { get; set; } 42 | /// 43 | /// 消息ID 44 | /// 45 | public int userMessageId { get; set; } 46 | /// 47 | /// 到达时间 48 | /// 49 | public long recieveTime { get; set; } 50 | /// 51 | /// 消息体ID 52 | /// 53 | public int userMessageBodyId { get; set; } 54 | /// 55 | /// 阅读时间 56 | /// 57 | public long readTime { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/GetAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// 获取 11 | /// 12 | public class GetAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/GetMediaResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetMediaResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public string ContentType { get; set; } 18 | /// 19 | /// 20 | /// 21 | public string FileName { get; set; } 22 | /// 23 | /// 24 | /// 25 | public DateTime Date { get; set; } 26 | /// 27 | /// 28 | /// 29 | public string ContentLength { get; set; } 30 | 31 | private Stream stream; 32 | /// 33 | /// 34 | /// 35 | public Stream Stream 36 | { 37 | get { return stream; } 38 | set { stream = value; } 39 | } 40 | /// 41 | /// 保存文件 42 | /// 43 | /// 44 | public void SaveAs(string fileName) 45 | { 46 | using (FileStream fs = new FileStream(fileName, FileMode.Create)) 47 | { 48 | byte[] bytes = new byte[stream.Length]; 49 | int bytesRead = 0; 50 | int bytesToRead = (int)stream.Length; 51 | stream.Position = 0; 52 | while (bytesToRead > 0) 53 | { 54 | int n = stream.Read(bytes, bytesRead, Math.Min(bytesToRead, int.MaxValue)); 55 | if (n <= 0) 56 | { 57 | break; 58 | } 59 | fs.Write(bytes, bytesRead, n); 60 | bytesRead += n; 61 | bytesToRead -= n; 62 | } 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Api.Lanxin/Messages/GetMemberResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetMemberResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public IList openOrgMemberList { get; set; } 18 | } 19 | 20 | /// 21 | /// 成员信息属性 22 | /// 23 | public class MemberInfo 24 | { 25 | /// 26 | /// 成员id 27 | /// 28 | public int Id { get; set; } 29 | /// 30 | /// 成员名称 31 | /// 32 | public string name { get; set; } 33 | /// 34 | /// Email 35 | /// 36 | public string email { get; set; } 37 | /// 38 | /// 手机号 39 | /// 40 | public string mobile { get; set; } 41 | /// 42 | /// 成员在组织中的位置 43 | /// 44 | public string path { get; set; } 45 | /// 46 | /// 成员所在部门ID 47 | /// 48 | public int parentId { get; set; } 49 | /// 50 | /// 成员所在组织名称,一般和company一样。如果是集团公司,orgName为集团名称 51 | /// 52 | public string orgName { get; set; } 53 | /// 54 | /// 成员所在公司名称,对应蓝信中的“单位”,一般和orgName一样。如果为集团公司,company一般为集团子公司名称 55 | /// 56 | public string company { get; set; } 57 | /// 58 | /// 所属单位ID 59 | /// 60 | public string companyId { get; set; } 61 | /// 62 | /// 业务属性列表 63 | /// 64 | public string busiTags { get; set; } 65 | /// 66 | /// 序列号,如警号 67 | /// 68 | public string serialNumber { get; set; } 69 | /// 70 | /// 职务属性列表 71 | /// 72 | public string posiTags { get; set; } 73 | /// 74 | /// 备注,说明 75 | /// 76 | public string note { get; set; } 77 | /// 78 | /// 岗位类别 79 | /// 80 | public string secondPosition { get; set; } 81 | /// 82 | /// 联系方式扩展 83 | /// 84 | public dynamic contactExs { get; set; } 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/GetParentStructResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetParentStructResult : JsonResult 13 | { 14 | /// 15 | /// 分支机构列表 16 | /// 17 | public IList openOrgStructList { get; set; } 18 | /// 19 | /// 成员列表 20 | /// 21 | public IList openOrgMemberList { get; set; } 22 | } 23 | 24 | /// 25 | /// 分支机构 26 | /// 27 | public class OrgStructInfo 28 | { 29 | /// 30 | /// 分支ID 31 | /// 32 | public int Id { get; set; } 33 | /// 34 | /// 分支名称 35 | /// 36 | public string name { get; set; } 37 | /// 38 | /// 分支所在位置 39 | /// 40 | public string path { get; set; } 41 | /// 42 | /// 分支父级机构,为0时,表示当前节点为根节点 43 | /// 44 | public int parentId { get; set; } 45 | 46 | } 47 | 48 | /// 49 | /// 成员信息属性 50 | /// 51 | public class OrgMemberInfo 52 | { 53 | /// 54 | /// 成员id 55 | /// 56 | public int Id { get; set; } 57 | /// 58 | /// 成员名称 59 | /// 60 | public string name { get; set; } 61 | /// 62 | /// Email 63 | /// 64 | public string email { get; set; } 65 | /// 66 | /// 手机号 67 | /// 68 | public string mobile { get; set; } 69 | /// 70 | /// 成员在组织中的位置 71 | /// 72 | public string path { get; set; } 73 | /// 74 | /// 成员所在组织名称 75 | /// 76 | public string orgName { get; set; } 77 | /// 78 | /// 成员所在组织id 79 | /// 80 | public int orgId { get; set; } 81 | /// 82 | /// 成员所在公司 83 | /// 84 | public string company { get; set; } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/GetSnsOAuthAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// sns 获取access_token 返回的消息体 11 | /// 12 | public class GetSnsOAuthAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | /// 23 | /// 24 | /// 25 | public string refresh_token { get; set; } 26 | /// 27 | /// 28 | /// 29 | public string openid { get; set; } 30 | /// 31 | /// 32 | /// 33 | public string scope { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/GetSnsUserInfoResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Messages 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetSnsUserInfoResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public IList openOrgMemberList { get; set; } 18 | } 19 | /// 20 | /// 21 | /// 22 | public class SnsUserInfo 23 | { 24 | /// 25 | /// 成员id 26 | /// 27 | public int id { get; set; } 28 | /// 29 | /// 成员名称 30 | /// 31 | public string name { get; set; } 32 | /// 33 | /// 手机号或USERUUNIID 34 | /// 35 | public string mobile { get; set; } 36 | /// 37 | /// Email 38 | /// 39 | public string email { get; set; } 40 | /// 41 | /// 成员在组织中的位置 42 | /// 43 | public string path { get; set; } 44 | /// 45 | /// 46 | /// 47 | public string serialNumber { get; set; } 48 | /// 49 | /// 50 | /// 51 | public string position { get; set; } 52 | /// 53 | /// 54 | /// 55 | public string note { get; set; } 56 | /// 57 | /// 成员所在部门ID 58 | /// 59 | public string parentId { get; set; } 60 | /// 61 | /// 62 | /// 63 | public string companyId { get; set; } 64 | /// 65 | /// 66 | /// 67 | public string secondPosition { get; set; } 68 | /// 69 | /// 70 | /// 71 | public string userUniId { get; set; } 72 | /// 73 | /// 成员所在公司名称,对应蓝信中的“单位”,一般和orgName一样。如果为集团公司,company一般为集团子公司名称 74 | /// 75 | public string company { get; set; } 76 | /// 77 | /// 78 | /// 79 | public dynamic[] busiTags { get; set; } 80 | /// 81 | /// 82 | /// 83 | public dynamic[] posiTags { get; set; } 84 | /// 85 | /// 86 | /// 87 | public dynamic[] contactExs { get; set; } 88 | /// 89 | /// 成员所在组织名称,一般和company一样。如果是集团公司,orgName为集团名称 90 | /// 91 | public string orgName { get; set; } 92 | /// 93 | /// 94 | /// 95 | public string orgId { get; set; } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Api.Lanxin/Messages/SendMessageResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Api.Lanxin.Messages 7 | { 8 | /// 9 | /// 10 | /// 11 | public class SendMessageResult : JsonResult 12 | { 13 | /// 14 | /// 无效用户 15 | /// 16 | public string invaliduser { get; set; } 17 | /// 18 | /// 无效部门 19 | /// 20 | public string invalidparty { get; set; } 21 | /// 22 | /// 无效标签 23 | /// 24 | public string invalidtag { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /Api.Lanxin/Messages/UploadMediaResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Api.Lanxin.Messages 7 | { 8 | /// 9 | /// 10 | /// 11 | public class UploadMediaResult : JsonResult 12 | { 13 | private DateTime dateInit = new DateTime(1970, 1, 1); 14 | /// 15 | /// 媒体文件类型:分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb) 16 | /// 17 | public string type { get; set; } 18 | /// 19 | /// 媒体文件上传后获取的唯一标识 20 | /// 21 | public string media_id { get; set; } 22 | /// 23 | /// 媒体文件上传时间戳 24 | /// 25 | public double created_at { get; set; } 26 | 27 | /// 28 | /// 29 | /// 30 | public DateTime DateCreated 31 | { 32 | get 33 | { 34 | if (created_at > Math.Pow(10, 10)) 35 | { 36 | return dateInit.AddMilliseconds(created_at).ToLocalTime(); 37 | } 38 | return dateInit.AddSeconds(created_at).ToLocalTime(); 39 | } 40 | set 41 | { 42 | var startTime = TimeZone.CurrentTimeZone.ToLocalTime(dateInit); 43 | created_at = (int)(value - startTime).TotalSeconds; 44 | //created_at = (value - dateInit).TotalSeconds; 45 | } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Api.Lanxin/Models/PostMedia.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Lanxin.Models 8 | { 9 | /// 10 | /// 用于上传的媒体 11 | /// 12 | public class PostMedia 13 | { 14 | private Byte[] _byteData; 15 | /// 16 | /// 17 | /// 18 | public PostMedia() 19 | { 20 | 21 | } 22 | /// 23 | /// 文件名称 24 | /// 25 | public string Name { get; set; } 26 | /// 27 | /// 文件名称,包含路径 28 | /// 29 | public string FullName { get; set; } 30 | ///// 31 | ///// 内容类型 32 | ///// 33 | //public string ContentType { get; set; } 34 | ///// 35 | ///// 内容大小 36 | ///// 37 | //public int ContentLength { get; set; } 38 | /// 39 | /// 文件流 40 | /// 41 | public Byte[] ByteData 42 | { 43 | get { return _byteData; } 44 | set { _byteData = value; } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Api.Lanxin/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Lanxin")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Lanxin")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("fafdbe24-8df5-49d1-a4c6-e8588a307c07")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Api.Lanxin/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/App_Data/log4net.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace Api.Weixin.Demo 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Set width on the form input elements since they're 100% wide by default */ 13 | input, 14 | select, 15 | textarea { 16 | max-width: 280px; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using Api.Core; 7 | using qy = Api.Weixin.Qy; 8 | 9 | namespace Api.Weixin.Demo.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | // GET: Home 14 | public ActionResult Index() 15 | { 16 | string corpId = "", corpSecret = ""; 17 | 18 | // 如何使用 19 | var access_token = qy.TokenManager.Instance(). 20 | GetAccessToken(corpId, corpSecret); 21 | 22 | qy.ApiHelper.Instance().CreateUser(access_token, new Qy.CreateUserRequest 23 | { 24 | email = "", 25 | 26 | }); 27 | return View(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Api.Weixin.Demo/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="Api.Weixin.Demo.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using Api.Core.Logging; 2 | using Api.Core.Logging.Log4Net; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Web; 7 | using System.Web.Mvc; 8 | using System.Web.Routing; 9 | 10 | namespace Api.Weixin.Demo 11 | { 12 | public class MvcApplication : System.Web.HttpApplication 13 | { 14 | protected void Application_Start() 15 | { 16 | AreaRegistration.RegisterAllAreas(); 17 | RouteConfig.RegisterRoutes(RouteTable.Routes); 18 | 19 | //为了调试方便加入日志,否则启用NullLogger 20 | LoggerFactory.InitializeLogFactory(new Log4NetLoggerFactoryAdapter(Server.MapPath("~/app_data/log4net.config"))); 21 | LoggerFactory.GetLogger().Debug("站点启动"); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/MessageProcessors/Hanlders/IMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using Api.Core.XmlModels; 2 | 3 | namespace Api.Weixin.Demo.MessageProcessors.Hanlders 4 | { 5 | /// 6 | /// 消息具体的处理器 7 | /// 8 | /// 9 | public interface IMessageHandler 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | IResponseMessage Handle(T message); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/MessageProcessors/Hanlders/QyMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using Api.Core.XmlModels; 2 | using System; 3 | 4 | namespace Api.Weixin.Demo.MessageProcessors.Hanlders 5 | { 6 | public class QyMessageHandler : IMessageHandler, 7 | IMessageHandler 8 | { 9 | public QyMessageHandler() 10 | { 11 | 12 | } 13 | 14 | public IResponseMessage Handle(ReceiveMessageText message) 15 | { 16 | ResponseMessage r = new ResponseMessage(); 17 | r.SetText("消息被处理了"); 18 | r.SetCreateTime(DateTime.Now); 19 | r.ToUserName = message.FromUserName; 20 | r.FromUserName = message.ToUserName; 21 | 22 | #region switch 23 | switch (message.Content) 24 | { 25 | case "11": 26 | 27 | break; 28 | case "12": 29 | 30 | r.SetImage(new ResponseMessageImage 31 | { 32 | MediaId = "1mzGcGxSGcChgUalQE6ZirdUcMXJbPrWdZDTPRiOGHU95MsSoTDvv6yJ85gNR-p1B" 33 | }); 34 | 35 | break; 36 | case "13": 37 | 38 | r.SetVoice(new ResponseMessageVoice 39 | { 40 | MediaId = "1mzGcGxSGcChgUalQE6ZirdUcMXJbPrWdZDTPRiOGHU95MsSoTDvv6yJ85gNR-p1B" 41 | }); 42 | 43 | break; 44 | case "-help": 45 | default: 46 | 47 | r.SetText("[11] 重新生成菜单。\r\n[12] Image。\r\n[13] Vioce。\r\n[-help] 查看帮助。"); 48 | 49 | break; 50 | } 51 | #endregion 52 | 53 | return r; 54 | } 55 | 56 | public IResponseMessage Handle(ReceiveMessageVideo message) 57 | { 58 | throw new NotImplementedException(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/MessageProcessors/IMessageProcessor.cs: -------------------------------------------------------------------------------- 1 | using Api.Core.XmlModels; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace Api.Weixin.Demo.MessageProcessors 8 | { 9 | /// 10 | /// 11 | /// 12 | public interface IMessageProcessor 13 | { 14 | /// 15 | /// 处理消息并返回处理结果 16 | /// 17 | /// 18 | IResponseMessage Process(); 19 | } 20 | } -------------------------------------------------------------------------------- /Api.Weixin.Demo/MessageProcessors/ReceiveMessageProcessor.cs: -------------------------------------------------------------------------------- 1 | using Api.Core.Enums; 2 | using Api.Core.Helpers; 3 | using Api.Core.XmlModels; 4 | using Api.Weixin.Demo.MessageProcessors.Hanlders; 5 | 6 | namespace Api.Weixin.Demo.MessageProcessors 7 | { 8 | public class ReceiveMessageProcessor 9 | { 10 | private IReceiveMessage _receiveMessage; 11 | private string _xmlMessage; 12 | public ReceiveMessageProcessor(string xmlMessage) 13 | { 14 | _xmlMessage = xmlMessage; 15 | } 16 | /// 17 | /// 18 | /// 19 | /// 20 | public virtual IResponseMessage Process() 21 | { 22 | var messageHandler = new QyMessageHandler(); 23 | _receiveMessage = XmlHelper.Deserialize(_xmlMessage); 24 | 25 | switch (_receiveMessage.MsgType) 26 | { 27 | case ReceiveMessageType.text: 28 | _receiveMessage = XmlHelper.Deserialize(_xmlMessage); 29 | return (messageHandler as IMessageHandler).Handle(_receiveMessage as ReceiveMessageText); 30 | //break; 31 | case ReceiveMessageType.image: 32 | _receiveMessage = XmlHelper.Deserialize(_xmlMessage); 33 | return (messageHandler as IMessageHandler).Handle(_receiveMessage as ReceiveMessageImage); 34 | //break; 35 | case ReceiveMessageType.voice: 36 | _receiveMessage = XmlHelper.Deserialize(_xmlMessage); 37 | return (messageHandler as IMessageHandler).Handle(_receiveMessage as ReceiveMessageVoice); 38 | //break; 39 | case ReceiveMessageType.video: 40 | break; 41 | case ReceiveMessageType.location: 42 | break; 43 | case ReceiveMessageType.@event: 44 | break; 45 | case ReceiveMessageType.link: 46 | break; 47 | default: 48 | break; 49 | } 50 | 51 | return null; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Weixin.Demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Weixin.Demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("577a53f1-661c-4f4b-a312-f8e5ad7d478d")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Properties/PublishProfiles/release.pubxml: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | FileSystem 9 | Release 10 | Any CPU 11 | 12 | True 13 | False 14 | D:\wwwroot\api_weixin_demo_release 15 | True 16 | 17 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 |  2 | @{ 3 | ViewBag.Title = "Index"; 4 | } 5 | 6 |

Index

7 | 8 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewBag.Title - My ASP.NET Application 7 | 8 | 9 | 10 | 11 | 12 | 28 | 29 |
30 | @RenderBody() 31 |
32 |
33 |

© @DateTime.Now.Year - My ASP.NET Application

34 |
35 |
36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } -------------------------------------------------------------------------------- /Api.Weixin.Demo/Views/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Api.Weixin.Demo/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaryway/api/61cf301b1f5160c1eb1b4b7e892d2f09a08486dd/Api.Weixin.Demo/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /Api.Weixin.Demo/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaryway/api/61cf301b1f5160c1eb1b4b7e892d2f09a08486dd/Api.Weixin.Demo/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /Api.Weixin.Demo/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaryway/api/61cf301b1f5160c1eb1b4b7e892d2f09a08486dd/Api.Weixin.Demo/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /Api.Weixin.Demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Extensions/MpAPIHelperExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using API.Helpers; 6 | 7 | namespace API.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public static class MpAPIHelperExtensions 13 | { 14 | /// 15 | /// 获取MpHelper,MpHelper是关于公众号的方法,避免方法名称冲突 16 | /// 17 | /// 18 | /// 19 | public static MpHelper Mp(this APIHelper helper) 20 | { 21 | return MpHelper.Instance(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Extensions/MpTokenManagerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using API.Caching; 6 | using API.Helpers; 7 | using API.Qy; 8 | 9 | namespace API.Mp 10 | { 11 | /// 12 | /// 13 | /// 14 | public static class MpTokenManagerExtensions 15 | { 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | public static MpTokenManager Mp(this TokenManager manager) 22 | { 23 | return MpTokenManager.Instance(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/AddTemplateResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class AddTemplateResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public string template_id { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/CreateGroupResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class CreateGroupResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public Group group { get; set; } 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetCallbackIPResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetCallbackIPResult : JsonResult 13 | { 14 | /// 15 | /// 微信服务器IP地址列表 16 | /// 17 | public string[] ip_list { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetGroupIdByOpenIdResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 查询用户所在分组结果 11 | /// 12 | public class GetGroupIdByOpenIdResult : JsonResult 13 | { 14 | /// 15 | /// 用户所属的groupid 16 | /// 17 | public int groupid { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetGroupListResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 查询所有分组结果 11 | /// 12 | public class GetGroupListResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public IList groups { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetKFListResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetKFListResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public KFInfo[] kf_list { get; set; } 18 | } 19 | /// 20 | /// 21 | /// 22 | public class KFInfo 23 | { 24 | /// 25 | /// 26 | /// 27 | public string kf_id { get; set; } 28 | /// 29 | /// 30 | /// 31 | public string kf_account { get; set; } 32 | /// 33 | /// 34 | /// 35 | public string kf_nick { get; set; } 36 | /// 37 | /// 38 | /// 39 | public string kf_headimgurl { get; set; } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetMassMessageResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 查询群发消息发送状态 11 | /// 12 | public class GetMassMessageResult : JsonResult 13 | { 14 | /// 15 | /// 群发消息后返回的消息id 16 | /// 17 | public long msg_id { get; set; } 18 | /// 19 | /// 消息发送后的状态,SEND_SUCCESS表示发送成功 20 | /// 21 | public string msg_status { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetMediaResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Web; 7 | 8 | namespace Api.Weixin.Mp 9 | { 10 | /// 11 | /// 12 | /// 13 | public class GetMediaResult : JsonResult 14 | { 15 | /// 16 | /// 17 | /// 18 | public string ContentType { get; set; } 19 | /// 20 | /// 21 | /// 22 | public string FileName { get; set; } 23 | /// 24 | /// 25 | /// 26 | public DateTime Date { get; set; } 27 | /// 28 | /// 29 | /// 30 | public string ContentLength { get; set; } 31 | 32 | private Stream stream; 33 | /// 34 | /// 35 | /// 36 | public Stream Stream 37 | { 38 | get { return stream; } 39 | set { stream = value; } 40 | } 41 | /// 42 | /// 保存文件 43 | /// 44 | /// 45 | public void SaveAs(string fileName) 46 | { 47 | using (FileStream fs = new FileStream(fileName, FileMode.Create)) 48 | { 49 | byte[] bytes = new byte[stream.Length]; 50 | int bytesRead = 0; 51 | int bytesToRead = (int)stream.Length; 52 | stream.Position = 0; 53 | while (bytesToRead > 0) 54 | { 55 | int n = stream.Read(bytes, bytesRead, Math.Min(bytesToRead, int.MaxValue)); 56 | if (n <= 0) 57 | { 58 | break; 59 | } 60 | fs.Write(bytes, bytesRead, n); 61 | bytesRead += n; 62 | bytesToRead -= n; 63 | } 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetSNSAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetSNSAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | /// 23 | /// 用户刷新access_token 24 | /// 25 | public string refresh_token { get; set; } 26 | /// 27 | /// 用户唯一标识 28 | /// 29 | public string openid { get; set; } 30 | /// 31 | /// 用户授权的作用域,使用逗号(,)分隔 32 | /// 33 | public string scope { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetSNSUserInfoResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 拉取用户信息(需scope为 snsapi_userinfo) 11 | /// 12 | public class GetSNSUserInfoResult : JsonResult 13 | { 14 | //"openid":" OPENID", 15 | //"nickname": NICKNAME, 16 | //"sex":"1", 17 | //"province":"PROVINCE" 18 | //"city":"CITY", 19 | //"country":"COUNTRY", 20 | //"headimgurl": "http://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46", 21 | //"privilege":[ "PRIVILEGE1" "PRIVILEGE2" ], 22 | //"unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL" 23 | 24 | /// 25 | /// 用户的标识,对当前公众号唯一 26 | /// 27 | public string openid { get; set; } 28 | /// 29 | /// 用户的昵称 30 | /// 31 | public string nickname { get; set; } 32 | /// 33 | /// 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 34 | /// 35 | public int sex { get; set; } 36 | /// 37 | /// 用户所在省份 38 | /// 39 | public string province { get; set; } 40 | /// 41 | /// 用户所在城市 42 | /// 43 | public string city { get; set; } 44 | /// 45 | /// 用户所在国家 46 | /// 47 | public string country { get; set; } 48 | /// 49 | /// 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。 50 | /// 51 | public string headimgurl { get; set; } 52 | /// 53 | /// 用户特权信息,json 数组,如微信沃卡用户为(chinaunicom) 54 | /// 55 | public string[] privilege { get; set; } 56 | /// 57 | /// 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。 58 | /// 59 | public string unionid { get; set; } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetShortUrlResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetShortUrlResult : JsonResult 13 | { 14 | /// 15 | /// 换取到的短链接 16 | /// 17 | public string short_url { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetUserInfoResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetUserInfoResult : JsonResult 13 | { 14 | /// 15 | /// 用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。 16 | /// 17 | public int subscribe { get; set; } 18 | /// 19 | /// 用户的标识,对当前公众号唯一 20 | /// 21 | public string openid { get; set; } 22 | /// 23 | /// 用户的昵称 24 | /// 25 | public string nickname { get; set; } 26 | /// 27 | /// 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 28 | /// 29 | public int sex { get; set; } 30 | /// 31 | /// 用户所在城市 32 | /// 33 | public string city { get; set; } 34 | /// 35 | /// 用户所在国家 36 | /// 37 | public string country { get; set; } 38 | /// 39 | /// 用户所在省份 40 | /// 41 | public string province { get; set; } 42 | /// 43 | /// 用户的语言,简体中文为zh_CN 44 | /// 45 | public string language { get; set; } 46 | /// 47 | /// 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。 48 | /// 49 | public string headimgurl { get; set; } 50 | /// 51 | /// 用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间 52 | /// 53 | public int subscribe_time { get; set; } 54 | /// 55 | /// 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。详见:获取用户个人信息(UnionID机制) 56 | /// 57 | public string unionid { get; set; } 58 | /// 59 | /// 公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注 60 | /// 61 | public string remark { get; set; } 62 | /// 63 | /// 用户所在的分组ID 64 | /// 65 | public int groupid { get; set; } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/GetUserListResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 获取用户列表结果 11 | /// 12 | public class GetUserListResult : JsonResult 13 | { 14 | /// 15 | /// 关注该公众账号的总用户数 16 | /// 17 | public int total { get; set; } 18 | /// 19 | /// 拉取的OPENID个数,最大值为10000 20 | /// 21 | public int count { get; set; } 22 | /// 23 | /// 列表数据,OPENID的列表 24 | /// 25 | public OpenIdList data { get; set; } 26 | /// 27 | /// 拉取列表的后一个用户的OPENID 28 | /// 29 | public string next_openid { get; set; } 30 | 31 | /// 32 | /// OPENID的列表 33 | /// 34 | public class OpenIdList { IList openid { get; set; } } 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/SendKFMessageRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using Api.Core.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Api.Weixin.Mp 9 | { 10 | /// 11 | /// 客服消息 12 | /// 13 | public class SendKFMessageRequest : IRequest 14 | { 15 | /// 16 | /// 普通用户openid 17 | /// 18 | public string touser { get; set; } 19 | /// 20 | /// 消息类型,文本为text,图片为image,语音为voice,视频消息为video,音乐消息为music,图文消息为news,卡券为wxcard 21 | /// 22 | public string msgtype { get; set; } 23 | /// 24 | /// 发送文本消息 25 | /// 26 | public Text text { get; set; } 27 | /// 28 | /// 发送图片消息 29 | /// 30 | public Image image { get; set; } 31 | /// 32 | /// 发送语音消息 33 | /// 34 | public Voice voice { get; set; } 35 | /// 36 | /// 发送视频消息 37 | /// 38 | public Video video { get; set; } 39 | /// 40 | /// 发送音乐消息 41 | /// 42 | public Music music { get; set; } 43 | 44 | /// 45 | /// 发送图文消息 46 | /// 47 | public News news { get; set; } 48 | /// 49 | /// 发送卡券 50 | /// 51 | public wxcard wxcard { get; set; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/SendMassMessageResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 群发消息结果 11 | /// 12 | public class SendMassMessageResult : JsonResult 13 | { 14 | /// 15 | /// 消息ID 16 | /// 17 | public int msg_id { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/SendTemplateMessageRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 发送模板消息请求 11 | /// 12 | public class SendTemplateMessageRequest : IRequest 13 | { 14 | /// 15 | /// 接收者的openID 16 | /// 17 | public string touser { get; set; } 18 | /// 19 | /// 模板ID 20 | /// 21 | public string template_id { get; set; } 22 | /// 23 | /// 链接地址 24 | /// 25 | public string url { get; set; } 26 | /// 27 | /// 顶部颜色 28 | /// 29 | public string topcolor { get; set; } 30 | 31 | /// 32 | /// 模板数据 33 | /// 34 | public Data data { get; set; } 35 | 36 | /// 37 | /// 38 | /// 39 | public class Data 40 | { 41 | /// 42 | /// 43 | /// 44 | public DataItem first { get; set; } 45 | /// 46 | /// 47 | /// 48 | public DataItem keynote1 { get; set; } 49 | /// 50 | /// 51 | /// 52 | public DataItem keynote2 { get; set; } 53 | /// 54 | /// 55 | /// 56 | public DataItem keynote3 { get; set; } 57 | /// 58 | /// 59 | /// 60 | public DataItem remark { get; set; } 61 | } 62 | /// 63 | /// 64 | /// 65 | public class DataItem 66 | { 67 | /// 68 | /// 69 | /// 70 | public string value { get; set; } 71 | /// 72 | /// 73 | /// 74 | public string color { get; set; } 75 | } 76 | } 77 | 78 | /// 79 | /// 80 | /// 81 | public class TemplateMessageData 82 | { 83 | //public 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/SendTemplateMessageResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 发送模板消息请求结果 11 | /// 12 | public class SendTemplateMessageResult : JsonResult 13 | { 14 | /// 15 | /// 消息ID 16 | /// 17 | public long msgid { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/UploadMediaNewsRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using Api.Core.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Api.Weixin.Mp 9 | { 10 | /// 11 | /// 上传图文消息素材 12 | /// 13 | public class UploadMediaNewsRequest : IRequest 14 | { 15 | /// 16 | /// 图文消息,一个图文消息支持1到10条图文 17 | /// 18 | public IList articles { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/UploadMediaNewsResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp 8 | { 9 | /// 10 | /// 上传图文消息素材 11 | /// 12 | public class UploadMediaNewsResult : JsonResult 13 | { 14 | /// 15 | /// 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb),次数为news,即图文消息 16 | /// 17 | public string type { get; set; } 18 | /// 19 | /// 媒体文件/图文消息上传后获取的唯一标识 20 | /// 21 | public string media_id { get; set; } 22 | /// 23 | /// 媒体文件上传时间 24 | /// 25 | public int created_at { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Messages/UploadMediaResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Api.Weixin.Mp 7 | { 8 | /// 9 | /// 10 | /// 11 | public class UploadMediaResult 12 | { 13 | private DateTime dateInit = new DateTime(1970, 1, 1, 0, 0, 0); 14 | 15 | private int _errcode = 0; 16 | /// 17 | /// 错误代码 18 | /// 19 | public int errcode 20 | { 21 | get { return _errcode; } 22 | set { _errcode = value; } 23 | } 24 | /// 25 | /// 错误信息 26 | /// 27 | public string errmsg { get; set; } 28 | 29 | 30 | /// 31 | /// 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file) 32 | /// 33 | public string type { get; set; } 34 | /// 35 | /// 媒体文件上传后获取的唯一标识 36 | /// 37 | public string media_id { get; set; } 38 | /// 39 | /// 媒体文件上传时间戳 40 | /// 41 | public double created_at { get; set; } 42 | 43 | /// 44 | /// 45 | /// 46 | public DateTime DateCreated 47 | { 48 | get { return dateInit.AddSeconds(created_at).ToLocalTime(); } 49 | set { created_at = (value - dateInit).TotalSeconds; } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Api.Weixin.Mp/Models/Group.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Mp 7 | { 8 | /// 9 | /// 分组 10 | /// 11 | public class Group 12 | { 13 | private int _count = 0; 14 | /// 15 | /// 分组id,由微信分配 16 | /// 17 | public int id { get; set; } 18 | /// 19 | /// 分组名字,UTF8编码 20 | /// 21 | public string name { get; set; } 22 | /// 23 | /// 分组内用户数量 24 | /// 25 | public int count 26 | { 27 | get { return _count; } 28 | set { _count = value; } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Models/KFMessage.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using Api.Core.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Api.Weixin.Mp 9 | { 10 | /// 11 | /// 12 | /// 13 | public class KFMessage 14 | { 15 | /// 16 | /// 17 | /// 18 | public string touser { get; set; } 19 | /// 20 | /// 21 | /// 22 | public string msgtype { get; set; } 23 | /// 24 | /// 25 | /// 26 | public Text text { get; set; } 27 | /// 28 | /// 29 | /// 30 | public Image image { get; set; } 31 | /// 32 | /// 33 | /// 34 | public Voice voice { get; set; } 35 | /// 36 | /// 37 | /// 38 | public Video video { get; set; } 39 | /// 40 | /// 41 | /// 42 | public Music music { get; set; } 43 | 44 | /// 45 | /// 46 | /// 47 | public News news { get; set; } 48 | /// 49 | /// 50 | /// 51 | public wxcard wxcard { get; set; } 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/GetAuthorizerInfoResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetAuthorizerInfoResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public authorizerInfo authorizer_info { get; set; } 18 | 19 | /// 20 | /// 二维码图片的URL,开发者最好自行也进行保存 21 | /// 22 | public string qrcode_url { get; set; } 23 | /// 24 | /// 25 | /// 26 | public authorizationInfo authorization_info { get; set; } 27 | 28 | /// 29 | /// 30 | /// 31 | public class authorizerInfo 32 | { 33 | /// 34 | /// 35 | /// 36 | public string nick_name { get; set; } 37 | /// 38 | /// 39 | /// 40 | public string head_img { get; set; } 41 | /// 42 | /// 授权方公众号类型,0代表订阅号,1代表由历史老帐号升级后的订阅号,2代表服务号 43 | /// 44 | public string service_type_info { get; set; } 45 | /// 46 | /// 授权方认证类型,-1代表未认证,0代表微信认证,1代表新浪微博认证,2代表腾讯微博认证,3代表已资质认证通过但还未通过名称认证,4代表已资质认证通过、还未通过名称认证,但通过了新浪微博认证,5代表已资质认证通过、还未通过名称认证,但通过了腾讯微博认证 47 | /// 48 | public string verify_type_info { get; set; } 49 | /// 50 | /// 授权方公众号的原始ID 51 | /// 52 | public string user_name { get; set; } 53 | /// 54 | /// 授权方公众号所设置的微信号,可能为空 55 | /// 56 | public string alias { get; set; } 57 | 58 | } 59 | /// 60 | /// 授权信息 61 | /// 62 | public class authorizationInfo 63 | { 64 | /// 65 | /// 授权方appid 66 | /// 67 | public string appid { get; set; } 68 | /// 69 | /// 公众号授权给开发者的权限集列表 70 | /// 71 | public IList func_info { get; set; } 72 | 73 | } 74 | /// 75 | /// 授权方公众号类型 76 | /// 77 | public class service_type_info 78 | { 79 | /// 80 | /// 81 | /// 82 | public int id { get; set; } 83 | } 84 | 85 | /// 86 | /// 授权方认证类型 87 | /// 88 | public class verify_type_info 89 | { 90 | /// 91 | /// 92 | /// 93 | public int id { get; set; } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/GetAuthorizerOptionResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetAuthorizerOptionResult : JsonResult 13 | { 14 | /// 15 | /// 授权公众号appid 16 | /// 17 | public string authorizer_appid { get; set; } 18 | /// 19 | /// 选项名称 20 | /// 21 | public string option_name { get; set; } 22 | /// 23 | /// 选项值 24 | /// 25 | public string option_value { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/GetComponentAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetComponentAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string component_access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/GetComponentPreAuthCodeResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetComponentPreAuthCodeResult : JsonResult 13 | { 14 | /// 15 | /// 预授权码 16 | /// 17 | public string pre_auth_code { get; set; } 18 | /// 19 | /// 有效期,为20分钟 20 | /// 21 | public int expires_in { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/GetSNSAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetSNSAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | /// 23 | /// 用户刷新access_token 24 | /// 25 | public string refresh_token { get; set; } 26 | /// 27 | /// 授权用户唯一标识 28 | /// 29 | public string openid { get; set; } 30 | /// 31 | /// 用户授权的作用域,使用逗号(,)分隔 32 | /// 33 | public string scope { get; set; } 34 | /// 35 | /// 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。 36 | /// 37 | public string unionid { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/GetUserInfoResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetUserInfoResult : JsonResult 13 | { 14 | /// 15 | /// 普通用户的标识,对当前开发者帐号唯一 16 | /// 17 | public string openid { get; set; } 18 | /// 19 | /// 普通用户昵称 20 | /// 21 | public string nickname { get; set; } 22 | /// 23 | /// 普通用户性别,1为男性,2为女性 24 | /// 25 | public int sex { get; set; } 26 | /// 27 | /// 普通用户个人资料填写的省份 28 | /// 29 | public string province { get; set; } 30 | /// 31 | /// 普通用户个人资料填写的城市 32 | /// 33 | public string city { get; set; } 34 | /// 35 | /// 国家,如中国为CN 36 | /// 37 | public string country { get; set; } 38 | /// 39 | /// 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空 40 | /// 41 | public string headimgurl { get; set; } 42 | /// 43 | /// 用户特权信息,json数组,如微信沃卡用户为(chinaunicom) 44 | /// 45 | public IList privilege { get; set; } 46 | /// 47 | /// 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。 48 | /// 49 | public string unionid { get; set; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/QueryComponentAuthResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class QueryComponentAuthResult : JsonResult 13 | { 14 | /// 15 | /// 授权信息 16 | /// 17 | public authorizationInfo authorization_info { get; set; } 18 | 19 | /// 20 | /// 授权信息 21 | /// 22 | public class authorizationInfo 23 | { 24 | /// 25 | /// 授权方appid 26 | /// 27 | public string authorizer_appid { get; set; } 28 | /// 29 | /// 授权方令牌(在授权的公众号具备API权限时,才有此返回值) 30 | /// 31 | public string authorizer_access_token { get; set; } 32 | /// 33 | /// 有效期(在授权的公众号具备API权限时,才有此返回值) 34 | /// 35 | public int expires_in { get; set; } 36 | /// 37 | /// 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于公众号第三方平台获取和刷新已授权用户的access_token,只会在授权时刻提供,请妥善保存。 一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌 38 | /// 39 | public string authorizer_refresh_token { get; set; } 40 | 41 | /// 42 | /// 公众号授权给开发者的权限集列表(请注意,当出现用户已经将消息与菜单权限集授权给了某个第三方,再授权给另一个第三方时,由于该权限集是互斥的,后一个第三方的授权将去除此权限集,开发者可以在返回的func_info信息中验证这一点,避免信息遗漏),1到8分别代表: 43 | /// 消息与菜单权限集 44 | /// 用户管理权限集 45 | /// 帐号管理权限集 46 | /// 网页授权权限集 47 | /// 微信小店权限集 48 | /// 多客服权限集 49 | /// 业务通知权限集 50 | /// 微信卡券权限集 51 | /// 52 | public IList func_info { get; set; } 53 | } 54 | 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/RefreshAuthorizerTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class RefreshAuthorizerTokenResult : JsonResult 13 | { 14 | /// 15 | /// 授权方令牌(在授权的公众号具备API权限时,才有此返回值) 16 | /// 17 | public string authorizer_access_token { get; set; } 18 | /// 19 | /// 有效期(在授权的公众号具备API权限时,才有此返回值) 20 | /// 21 | public int expires_in { get; set; } 22 | /// 23 | /// 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于公众号第三方平台获取和刷新已授权用户的access_token,只会在授权时刻提供,请妥善保存。 一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌 24 | /// 25 | public string authorizer_refresh_token { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/RefreshSNSAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 刷新access_token(如果需要) 11 | /// 12 | public class RefreshSNSAccessTokenResult : JsonResult 13 | { 14 | /// 15 | /// 获取到的凭证 16 | /// 17 | public string access_token { get; set; } 18 | /// 19 | /// 凭证有效时间,单位:秒 20 | /// 21 | public int expires_in { get; set; } 22 | /// 23 | /// 用户刷新access_token 24 | /// 25 | public string refresh_token { get; set; } 26 | /// 27 | /// 授权用户唯一标识 28 | /// 29 | public string openid { get; set; } 30 | /// 31 | /// 用户授权的作用域,使用逗号(,)分隔 32 | /// 33 | public string scope { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Messages/SetAuthorizerOptionResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Mp.Open 8 | { 9 | /// 10 | /// 11 | /// 12 | public class SetAuthorizerOptionResult : JsonResult 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Open/Models/funcscope_category.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Mp.Open 7 | { 8 | /// 9 | /// 公众号授权给开发者的权限集列表 10 | /// 11 | public class funcscope_category 12 | { 13 | /// 14 | /// 15 | /// 16 | public int id { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Weixin.Mp")] 9 | [assembly: AssemblyDescription("微信公众号API")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Weixin.Mp")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("da79adb4-03bd-443e-b00e-25aeff19b1e1")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.1.2.1")] 36 | [assembly: AssemblyFileVersion("1.1.2.1")] 37 | -------------------------------------------------------------------------------- /Api.Weixin.Mp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Config/DefaultWePayConfigAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Api.Weixin.Pay.Models; 6 | 7 | namespace Api.Weixin.Pay 8 | { 9 | /// 10 | /// 11 | /// 12 | public class DefaultWePayConfigAdapter : IWePayConfigAdapter 13 | { 14 | /// 15 | /// 16 | /// 17 | /// 18 | public WePayConfig Get() 19 | { 20 | var config = new WePayConfig(); 21 | config.APPID = System.Configuration.ConfigurationManager.AppSettings["wepay:appid"]; 22 | config.KEY = System.Configuration.ConfigurationManager.AppSettings["wepay:key"]; 23 | config.MCHID = System.Configuration.ConfigurationManager.AppSettings["wepay:mchid"]; 24 | config.APPSECRET = System.Configuration.ConfigurationManager.AppSettings["wepay:appsecret"]; 25 | config.NOTIFY_URL = System.Configuration.ConfigurationManager.AppSettings["wepay:notify_url"]; 26 | config.SSLCERT_PATH = System.Configuration.ConfigurationManager.AppSettings["wepay:sslcert_path"]; 27 | config.SSLCERT_PASSWORD = System.Configuration.ConfigurationManager.AppSettings["wepay:sslcert_password"]; 28 | var s = System.Configuration.ConfigurationManager.AppSettings["wepay:report_levenl"]; 29 | config.REPORT_LEVENL = int.Parse(string.IsNullOrEmpty(s) ? "0" : "1"); 30 | return config; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Config/IWePayConfigAdapter.cs: -------------------------------------------------------------------------------- 1 | using Api.Weixin.Pay.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Pay 8 | { 9 | public interface IWePayConfigAdapter 10 | { 11 | WePayConfig Get(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Config/WePayConfigFactory.cs: -------------------------------------------------------------------------------- 1 | using Api.Weixin.Pay.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Pay 8 | { 9 | /// 10 | /// 11 | /// 12 | public class WePayConfigFactory 13 | { 14 | //[ThreadStatic] 15 | private static IWePayConfigAdapter _adapter; 16 | /// 17 | /// 18 | /// 19 | /// 20 | public static void Initialize(IWePayConfigAdapter adapter) 21 | { 22 | _adapter = adapter; 23 | } 24 | 25 | /// 26 | /// 获取支付配置,使用前请先初始化Initialize,如果没用初始化则使用默认配置 27 | /// 28 | /// 29 | public static WePayConfig Get() 30 | { 31 | if (_adapter == null) 32 | { 33 | _adapter = new DefaultWePayConfigAdapter(); 34 | } 35 | 36 | return _adapter.Get(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Fields/CloseOrderFields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay 7 | { 8 | /// 9 | /// 关闭订单字段 10 | /// 11 | public class CloseOrderFields 12 | { 13 | /// 14 | /// 公众账号ID,微信分配的公众账号ID(企业号corpid即为此appId) 15 | /// 16 | public const string appid = "appid"; 17 | /// 18 | /// 商户号,微信支付分配的商户号 19 | /// 20 | public const string mch_id = "mch_id"; 21 | /// 22 | /// 商户订单号,商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 23 | /// 24 | public const string out_trade_no = "out_trade_no"; 25 | /// 26 | /// 随机字符串,随机字符串,不长于32位。 27 | /// 28 | public const string nonce_str = "nonce_str"; 29 | /// 30 | /// 签名 31 | /// 32 | public const string sign = "sign"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Fields/DownloadBillFields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay.Fields 7 | { 8 | /// 9 | /// 10 | /// 11 | public class DownloadBillFields 12 | { 13 | /// 14 | /// 公众账号ID,微信分配的公众账号ID(企业号corpid即为此appId) 15 | /// 16 | public const string appid = "appid"; 17 | /// 18 | /// 商户号,微信支付分配的商户号 19 | /// 20 | public const string mch_id = "mch_id"; 21 | /// 22 | /// 设备号 23 | /// 24 | public const string device_info = "device_info"; 25 | /// 26 | /// 随机字符串,随机字符串,不长于32位。 27 | /// 28 | public const string nonce_str = "nonce_str"; 29 | /// 30 | /// 签名 31 | /// 32 | public const string sign = "sign"; 33 | /// 34 | /// 对账单日期 35 | /// 36 | public const string bill_date = "bill_date"; 37 | /// 38 | /// 账单类型 39 | /// 40 | public const string bill_type = "bill_type"; 41 | /// 42 | /// 压缩账单 43 | /// 44 | public const string tar_type = "tar_type"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Fields/OrderQueryFields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay 7 | { 8 | /// 9 | /// 10 | /// 11 | public class OrderQueryFields 12 | { 13 | /// 14 | /// 公众账号ID,微信分配的公众账号ID(企业号corpid即为此appId) 15 | /// 16 | public const string appid = "appid"; 17 | /// 18 | /// 商户号,微信支付分配的商户号 19 | /// 20 | public const string mch_id = "mch_id"; 21 | /// 22 | /// 微信的订单号(二选一),优先使用。 23 | /// 24 | public const string transaction_id = "transaction_id"; 25 | /// 26 | /// 商户订单号(二选一),商户系统内部的订单号,当没提供transaction_id时需要传这个。 27 | /// 28 | public const string out_trade_no = "out_trade_no"; 29 | /// 30 | /// 随机字符串,随机字符串,不长于32位。 31 | /// 32 | public const string nonce_str = "nonce_str"; 33 | /// 34 | /// 签名 35 | /// 36 | public const string sign = "sign"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Fields/RefundFields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay 7 | { 8 | /// 9 | /// 申请退款 10 | /// 11 | public class RefundFields 12 | { 13 | /// 14 | /// 公众账号ID,微信分配的公众账号ID(企业号corpid即为此appId) 15 | /// 16 | public const string appid = "appid"; 17 | /// 18 | /// 商户号,微信支付分配的商户号 19 | /// 20 | public const string mch_id = "mch_id"; 21 | /// 22 | /// 设备号 23 | /// 24 | public const string device_info = "device_info"; 25 | /// 26 | /// 随机字符串,随机字符串,不长于32位。 27 | /// 28 | public const string nonce_str = "nonce_str"; 29 | /// 30 | /// 签名 31 | /// 32 | public const string sign = "sign"; 33 | /// 34 | /// 微信的订单号(二选一),优先使用。 35 | /// 36 | public const string transaction_id = "transaction_id"; 37 | /// 38 | /// 商户订单号(二选一),商户系统内部的订单号,当没提供transaction_id时需要传这个。 39 | /// 40 | public const string out_trade_no = "out_trade_no"; 41 | /// 42 | /// 商户退款单号,商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 43 | /// 44 | public const string out_refund_no = "out_refund_no"; 45 | /// 46 | /// 订单金额,订单总金额,单位为分,只能为整数 47 | /// 48 | public const string total_fee = "total_fee"; 49 | /// 50 | /// 退款金额 51 | /// 52 | public const string refund_fee = "refund_fee"; 53 | /// 54 | /// 货币种类 55 | /// 56 | public const string refund_fee_type = "refund_fee_type"; 57 | /// 58 | /// 操作员 59 | /// 60 | public const string op_user_id = "op_user_id"; 61 | /// 62 | /// 退款资金来源 63 | /// 64 | public const string refund_account = "refund_account"; 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Fields/RefundQueryFields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay 7 | { 8 | /// 9 | /// 10 | /// 11 | public class RefundQueryFields 12 | { 13 | /// 14 | /// 公众账号ID,微信分配的公众账号ID(企业号corpid即为此appId) 15 | /// 16 | public const string appid = "appid"; 17 | /// 18 | /// 商户号,微信支付分配的商户号 19 | /// 20 | public const string mch_id = "mch_id"; 21 | /// 22 | /// 设备号 23 | /// 24 | public const string device_info = "device_info"; 25 | /// 26 | /// 随机字符串,随机字符串,不长于32位。 27 | /// 28 | public const string nonce_str = "nonce_str"; 29 | /// 30 | /// 签名 31 | /// 32 | public const string sign = "sign"; 33 | /// 34 | /// 微信的订单号(四选一),优先使用。 35 | /// 36 | public const string transaction_id = "transaction_id"; 37 | /// 38 | /// 商户订单号(四选一),商户系统内部的订单号,当没提供transaction_id时需要传这个。 39 | /// 40 | public const string out_trade_no = "out_trade_no"; 41 | /// 42 | /// 商户退款单号(四选一),商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 43 | /// 44 | public const string out_refund_no = "out_refund_no"; 45 | /// 46 | /// 微信退款单号,微信生成的退款单号,在申请退款接口有返回 47 | /// 48 | public const string refund_id = "refund_id"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Models/WePayConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay.Models 7 | { 8 | /// 9 | /// 10 | /// 11 | public class WePayConfig 12 | { 13 | /// 14 | /// 绑定支付的APPID(必须配置) 15 | /// 16 | public string APPID { get; set; } 17 | /// 18 | /// 商户号(必须配置) 19 | /// 20 | public string MCHID { get; set; } 21 | /// 22 | /// 商户支付密钥,参考开户邮件设置(必须配置) 23 | /// 24 | public string KEY { get; set; } 25 | /// 26 | /// 公众帐号SECERT(仅JSAPI支付的时候需要配置) 27 | /// 28 | public string APPSECRET { get; set; } 29 | /// 30 | /// 支付结果通知回调url,用于商户接收支付结果 31 | /// e.g.http://paysdk.weixin.qq.com/example/ResultNotifyPage.aspx 32 | /// 33 | public string NOTIFY_URL { get; set; } 34 | /// 35 | /// 证书地址,相对地址 36 | /// e.g. "cert/apiclient_cert.p12" 37 | /// 38 | public string SSLCERT_PATH { get; set; } 39 | /// 40 | /// 证书密码 41 | /// 42 | public string SSLCERT_PASSWORD { get; set; } 43 | /// 44 | /// 是否上报测试,0=不上报,1=上报 45 | /// 46 | public int REPORT_LEVENL { get; set; } 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Weixin.Pay")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Weixin.Pay")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("b954579d-0aae-4030-9258-a8e22a9fd9cc")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Api.Weixin.Pay/WePayException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Pay 7 | { 8 | /// 9 | /// 10 | /// 11 | public class WePayException : Exception 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public WePayException(string message) : base(message) { } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/AddTagMembersRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using Api.Core; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | public class AddTagMembersRequest : IRequest 13 | { 14 | /// 15 | /// 标签ID 16 | /// 17 | public int tagid { get; set; } 18 | /// 19 | /// 企业员工ID列表 eg. [ "user1","user2"] 20 | /// 21 | public IEnumerable userlist { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/AddTagMembersResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class AddTagMembersResult : JsonResult 9 | { 10 | /// 11 | /// 若部分userid非法,则返回 e.g. usr1|usr2|usr3 12 | /// 13 | public string invalidlist { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/ConvertOpenIdToUserIdResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class ConvertOpenIdToUserIdResult : JsonResult 9 | { 10 | /// 11 | /// 12 | /// 13 | public string userid { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/ConvertUserIdToOpenIdResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class ConvertUserIdToOpenIdResult : JsonResult 9 | { 10 | /// 11 | /// 12 | /// 13 | public string openid { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/CreateChatRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Qy 7 | { 8 | /// 9 | /// 会话信息 10 | /// 11 | public class CreateChatRequest 12 | { 13 | /// 14 | /// 会话id 15 | /// 16 | public string chatid { get; set; } 17 | /// 18 | /// 会话标题 19 | /// 20 | public string name { get; set; } 21 | /// 22 | /// 管理员userid 23 | /// 24 | public string owner { get; set; } 25 | /// 26 | /// 会话成员列表,成员用userid来标识 27 | /// 28 | public string[] userlist { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/CreateDepartmentRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 请求包结构体为: 11 | /// 12 | /// { 13 | /// "name": "广州研发中心", 14 | /// "parentid": "1", 15 | /// "order": "1" 16 | ///} 17 | /// 18 | /// 19 | public class CreateDepartmentRequest : IRequest 20 | { 21 | /// 22 | /// 23 | /// 24 | public int id { get; set; } 25 | /// 26 | /// 部门名称。长度限制为1~64个字符 27 | /// 28 | public string name { get; set; } 29 | /// 30 | /// 父亲部门id。根部门id为1 31 | /// 32 | public int parentid { get; set; } 33 | /// 34 | /// 在父部门中的次序。从1开始,数字越大排序越靠后 35 | /// 36 | public int order { get; set; } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/CreateDepartmentResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | public class CreateDepartmentResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public int id { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/CreateTagRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Api.Weixin.Qy 9 | { 10 | /// 11 | /// 12 | /// 13 | public class CreateTagRequest : IRequest 14 | { 15 | /// 16 | /// 标签ID 17 | /// 18 | public int tagid { get; set; } 19 | /// 20 | /// 标签名称 21 | /// 22 | public string tagname { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/CreateTagResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class CreateTagResult : JsonResult 9 | { 10 | /// 11 | /// 12 | /// 13 | public int tagid { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/DeleteTagUsersResult.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using Api.Core; 4 | 5 | namespace Api.Weixin.Qy 6 | { 7 | /// 8 | /// 9 | /// 10 | public class DeleteTagUsersResult : JsonResult 11 | { 12 | /// 13 | /// 若部分userid非法,则返回 e.g. usr1|usr2|usr3 14 | /// 15 | public string invalidlist { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetAccessTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class GetAccessTokenResult : JsonResult 9 | { 10 | /// 11 | /// 12 | /// 13 | public string access_token { get; set; } 14 | /// 15 | /// 过期时间 16 | /// 17 | public int expires_in { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetAgentListResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 获取应用概况列表 11 | /// 12 | public class GetAgentListResult : JsonResult 13 | { 14 | /// 15 | /// 应用列表 16 | /// 17 | public AgentInfo[] agentlist { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetChatResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | public class GetChatResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public ChatInfo chat_info { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetDepartmentResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Weixin.Qy 5 | { 6 | /// 7 | /// 8 | /// 9 | public class GetDepartmentResult : JsonResult 10 | { 11 | /// 12 | /// 13 | /// 14 | public IEnumerable department { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetJsapiTicketResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class GetJsapiTicketResult : JsonResult 9 | { 10 | /// 11 | /// 12 | /// 13 | public string ticket { get; set; } 14 | /// 15 | /// 16 | /// 17 | public int expires_in { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetMediaResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.IO; 4 | 5 | namespace Api.Weixin.Qy 6 | { 7 | /// 8 | /// 9 | /// 10 | public class GetMediaResult : JsonResult 11 | { 12 | /// 13 | /// 14 | /// 15 | public string ContentType { get; set; } 16 | /// 17 | /// 18 | /// 19 | public string FileName { get; set; } 20 | /// 21 | /// 22 | /// 23 | public DateTime Date { get; set; } 24 | /// 25 | /// 26 | /// 27 | public string ContentLength { get; set; } 28 | 29 | private Stream stream; 30 | /// 31 | /// 32 | /// 33 | public Stream Stream 34 | { 35 | get { return stream; } 36 | set { stream = value; } 37 | } 38 | /// 39 | /// 保存文件 40 | /// 41 | /// 42 | public void SaveAs(string fileName) 43 | { 44 | using (FileStream fs = new FileStream(fileName, FileMode.Create)) 45 | { 46 | byte[] bytes = new byte[stream.Length]; 47 | int bytesRead = 0; 48 | int bytesToRead = (int)stream.Length; 49 | stream.Position = 0; 50 | while (bytesToRead > 0) 51 | { 52 | int n = stream.Read(bytes, bytesRead, Math.Min(bytesToRead, int.MaxValue)); 53 | if (n <= 0) 54 | { 55 | break; 56 | } 57 | fs.Write(bytes, bytesRead, n); 58 | bytesRead += n; 59 | bytesToRead -= n; 60 | } 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetProviderTokenRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class GetProviderTokenRequest : IRequest 9 | { 10 | private string _corpid; 11 | private string _provider_secret; 12 | 13 | /// 14 | /// 企业号(提供商)的corpid 15 | /// 16 | public string corpid 17 | { 18 | get { return _corpid; } 19 | set { _corpid = value; } 20 | } 21 | /// 22 | /// 提供商的secret,在提供商管理页面可见 23 | /// 24 | public string provider_secret 25 | { 26 | get { return _provider_secret; } 27 | set { _provider_secret = value; } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetProviderTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | namespace Api.Weixin.Qy 3 | { 4 | /// 5 | /// 获取应用提供商凭证 6 | /// 7 | public class GetProviderTokenResult : JsonResult 8 | { 9 | private int _expires_in; 10 | private string _provider_access_token; 11 | /// 12 | /// accesstoken有效期 单位s 13 | /// 14 | public int expires_in 15 | { 16 | get { return _expires_in; } 17 | set { _expires_in = value; } 18 | } 19 | /// 20 | /// 服务提供商的accesstoken,可用于用户授权登录信息查询接口 21 | /// 22 | public string provider_access_token 23 | { 24 | get { return _provider_access_token; } 25 | set { _provider_access_token = value; } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetTagUserResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Weixin.Qy 5 | { 6 | /// 7 | /// 获取标签成员结果类 8 | /// 9 | public class GetTagUserResult : JsonResult 10 | { 11 | /// 12 | /// 用户列表 13 | /// 14 | public IEnumerable userlist { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetUserListResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Weixin.Qy 5 | { 6 | /// 7 | /// 8 | /// 9 | public class GetUserListResult : JsonResult 10 | { 11 | /// 12 | /// 用户列表 13 | /// 14 | public IEnumerable userlist { get; set; } 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetUserResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Weixin.Qy 5 | { 6 | /// 7 | /// 8 | /// 9 | public class GetUserResult : JsonResult 10 | { 11 | /// 12 | /// 员工UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字符 13 | /// 14 | public string userid { get; set; } 15 | /// 16 | /// 成员名称。长度为1~64个字符 17 | /// 18 | public string name { get; set; } 19 | /// 20 | /// 所在部门ID集合 21 | /// 22 | public List department { get; set; } 23 | /// 24 | /// 职位信息。长度为0~64个字符 25 | /// 26 | public string position { get; set; } 27 | /// 28 | /// 手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空 29 | /// 30 | public string mobile { get; set; } 31 | /// 32 | /// 性别。gender=0表示男,=1表示女。默认gender=0 33 | /// 34 | public int gender { get; set; } 35 | /// 36 | /// 办公电话。长度为0~64个字符 37 | /// 38 | public string tel { get; set; } 39 | /// 40 | /// 邮箱。长度为0~64个字符。企业内必须唯一 41 | /// 42 | public string email { get; set; } 43 | /// 44 | /// 微信号。企业内必须唯一 45 | /// 46 | public string weixinid { get; set; } 47 | /// 48 | /// 头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可 49 | /// 50 | public string avatar { get; set; } 51 | /// 52 | /// 关注状态: 1=已关注,2=已冻结,4=未关注 53 | /// 54 | public int status { get; set; } 55 | /// 56 | /// 扩展属性 57 | /// 58 | public UserExtensionAttribute extattr { get; set; } 59 | 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/GetUserSimpleListResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Weixin.Qy 5 | { 6 | /// 7 | /// 8 | /// 9 | public class GetUserSimpleListResult : JsonResult 10 | { 11 | 12 | /// 13 | /// 用户列表 14 | /// 15 | public IEnumerable userlist { get; set; } 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/OAuthAuthorizeResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | public class OAuthAuthorizeResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public OAuthAuthorizeResult() 18 | { 19 | errcode = -1; 20 | errmsg = "无效"; 21 | Target = ""; 22 | UserId = ""; 23 | DeviceId = ""; 24 | } 25 | 26 | /// 27 | /// 28 | /// 29 | /// 30 | public static OAuthAuthorizeResult New() 31 | { 32 | return new OAuthAuthorizeResult 33 | { 34 | errcode = -1, 35 | errmsg = "无效", 36 | Target = "", 37 | UserId = "", 38 | DeviceId = "" 39 | }; 40 | } 41 | /// 42 | /// 员工UserID 43 | /// 44 | public string UserId { get; set; } 45 | /// 46 | /// 手机设备号(由微信在安装时随机生成) 47 | /// 48 | public string DeviceId { get; set; } 49 | /// 50 | /// 目标页面URL 51 | /// 52 | public string Target { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/OAuthGetUserInfoResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class OAuthGetUserInfoResult : JsonResult 9 | { 10 | /// 11 | /// 员工UserID 12 | /// 13 | public string UserId { get; set; } 14 | /// 15 | /// 手机设备号(由微信在安装时随机生成) 16 | /// 17 | public string DeviceId { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/SendChatRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using Api.Core.Models; 3 | 4 | namespace Api.Weixin.Qy 5 | { 6 | /// 7 | /// 8 | /// 9 | public class SendChatRequest : IRequest 10 | { 11 | /// 12 | /// 接收人 13 | /// 14 | public ChatReceiver receiver { get; set; } 15 | /// 16 | /// 发送人 17 | /// 18 | public string sender { get; set; } 19 | /// 20 | /// 消息类型 21 | /// 22 | public string msgtype { get; set; } 23 | 24 | private Text _text; 25 | /// 26 | /// text消息 27 | /// 28 | public Text text 29 | { 30 | get { return _text; } 31 | set 32 | { 33 | _text = value; 34 | msgtype = "text"; 35 | } 36 | } 37 | 38 | private Image _image; 39 | /// 40 | /// 41 | /// 42 | public Image image 43 | { 44 | get { return _image; } 45 | set 46 | { 47 | _image = value; 48 | msgtype = "image"; 49 | } 50 | } 51 | 52 | private File _file; 53 | /// 54 | /// file消息 55 | /// 56 | public File file 57 | { 58 | get { return _file; } 59 | set 60 | { 61 | _file = value; 62 | msgtype = "file"; 63 | } 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/SendMessageResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | 4 | 5 | namespace Api.Weixin.Qy 6 | { 7 | /// 8 | /// 9 | /// 10 | public class SendMessageResult : JsonResult 11 | { 12 | /// 13 | /// 无效用户 14 | /// 15 | public string invaliduser { get; set; } 16 | /// 17 | /// 无效部门 18 | /// 19 | public string invalidparty { get; set; } 20 | /// 21 | /// 无效标签 22 | /// 23 | public string invalidtag { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/SetAgentRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Qy 7 | { 8 | /// 9 | /// 设置企业应用的选项设置信息 10 | /// 11 | public class SetAgentRequest 12 | { 13 | /// 14 | /// 企业应用的id 15 | /// 16 | public int agentid { get; set; } 17 | /// 18 | /// 企业应用是否打开地理位置上报 0:不上报;1:进入会话上报;2:持续上报 19 | /// 20 | public int report_location_flag { get; set; } 21 | /// 22 | /// 企业应用头像的mediaid,通过多媒体接口上传图片获得mediaid,上传后会自动裁剪成方形和圆形两个头像 23 | /// 24 | public string logo_mediaid { get; set; } 25 | /// 26 | /// 企业应用名称 27 | /// 28 | public string name { get; set; } 29 | /// 30 | /// 企业应用详情 31 | /// 32 | public string description { get; set; } 33 | /// 34 | /// 企业应用可信域名 35 | /// 36 | public string redirect_domain { get; set; } 37 | /// 38 | /// 是否接收用户变更通知。0:不接收;1:接收。 39 | /// 40 | public int isreportuser { get; set; } 41 | /// 42 | /// 是否上报用户进入应用事件。0:不接收;1:接收。 43 | /// 44 | public int isreportenter { get; set; } 45 | /// 46 | /// 主页型应用url。url必须以http或者https开头。消息型应用无需该参数 47 | /// 48 | public string home_url { get; set; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/SetMuteChatResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | public class SetMuteChatResult : JsonResult 13 | { 14 | /// 15 | /// 列表中不存在的成员会返回在invaliduser里,剩余合法成员会继续执行。 16 | /// 17 | public string[] invaliduser { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/UpdateChatRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class UpdateChatRequest : IRequest 9 | { 10 | /// 11 | /// 会话id 12 | /// 13 | public string chatid { get; set; } 14 | /// 15 | /// 操作人userid 16 | /// 17 | public string op_user { get; set; } 18 | /// 19 | /// 会话标题 20 | /// 21 | public string name { get; set; } 22 | /// 23 | /// 管理员userid,必须是该会话userlist的成员之一 24 | /// 25 | public string owner { get; set; } 26 | /// 27 | /// 会话新增成员列表,成员用userid来标识 28 | /// 29 | public string[] add_user_list { get; set; } 30 | /// 31 | /// 会话退出成员列表,成员用userid来标识 32 | /// 33 | public string[] del_user_list { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/UpdateTagRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class UploadTagRequest : IRequest 9 | { 10 | /// 11 | /// 标签ID 12 | /// 13 | public int tagid { get; set; } 14 | /// 15 | /// 标签名称 16 | /// 17 | public string tagname { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Messages/UploadMediaResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | public class UploadMediaResult : JsonResult 13 | { 14 | private DateTime dateInit = new DateTime(1970, 1, 1, 0, 0, 0); 15 | /// 16 | /// 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file) 17 | /// 18 | public string type { get; set; } 19 | /// 20 | /// 媒体文件上传后获取的唯一标识 21 | /// 22 | public string media_id { get; set; } 23 | /// 24 | /// 媒体文件上传时间戳 25 | /// 26 | public double created_at { get; set; } 27 | 28 | /// 29 | /// 30 | /// 31 | public DateTime DateCreated 32 | { 33 | get 34 | { 35 | if (created_at > Math.Pow(10, 10)) 36 | { 37 | return dateInit.AddMilliseconds(created_at).ToLocalTime(); 38 | } 39 | return dateInit.AddSeconds(created_at).ToLocalTime(); 40 | } 41 | set { created_at = (value - dateInit).TotalSeconds; } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/AgentInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Qy 7 | { 8 | /// 9 | /// 10 | /// 11 | public class AgentInfo 12 | { 13 | /// 14 | /// 应用id 15 | /// 16 | public string agentid { get; set; } 17 | /// 18 | /// 应用名称 19 | /// 20 | public string name { get; set; } 21 | /// 22 | /// 方形头像url 23 | /// 24 | public string square_logo_url { get; set; } 25 | /// 26 | /// 圆形头像url 27 | /// 28 | public string round_logo_url { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/ChatInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 7 | /// 8 | public class ChatInfo 9 | { 10 | /// 11 | /// 会话id 12 | /// 13 | public string chatid { get; set; } 14 | /// 15 | /// 会话标题 16 | /// 17 | public string name { get; set; } 18 | /// 19 | /// 管理员userid 20 | /// 21 | public string owner { get; set; } 22 | /// 23 | /// 会话成员列表,成员用userid来标识 24 | /// 25 | public string[] userlist { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/ChatReceiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace Api.Weixin.Qy 8 | { 9 | /// 10 | /// 11 | /// 12 | [XmlRoot("xml")] 13 | public class ChatReceiver 14 | { 15 | /// 16 | /// 接收人类型:single|group,分别表示:群聊|单聊 17 | /// 18 | public string type { get; set; } 19 | /// 20 | /// 接收人的值,为userid|chatid,分别表示:成员id|会话id 21 | /// 22 | public string id { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/Department.cs: -------------------------------------------------------------------------------- 1 | namespace Api.Weixin.Qy 2 | { 3 | /// 4 | /// 微信部门 5 | /// 6 | public class Department 7 | { 8 | /// 9 | /// 部门ID 10 | /// 11 | public int id { get; set; } 12 | /// 13 | /// 部门名称 14 | /// 15 | public string name { get; set; } 16 | /// 17 | /// 父级部门ID 18 | /// 19 | public int parentid { get; set; } 20 | /// 21 | /// 排序 22 | /// 23 | public int order { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/SetMuteChatInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Api.Weixin.Qy 2 | { 3 | /// 4 | /// 5 | /// 6 | public class SetMuteChatInfo 7 | { 8 | /// 9 | /// 成员UserID 10 | /// 11 | public string userid { get; set; } 12 | /// 13 | /// 免打扰状态,0关闭,1打开,默认为0。当打开时所有消息不提醒;当关闭时,以成员对会话的设置为准。 14 | /// 15 | public int status { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/UserExtensionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Api.Weixin.Qy 4 | { 5 | /// 6 | /// 用户额外属性 7 | /// 8 | public class UserExtensionAttribute 9 | { 10 | /// 11 | /// 12 | /// 13 | public List attrs { get; set; } 14 | 15 | /// 16 | /// 添加属性 17 | /// 18 | /// 19 | public void Add(UserExtensionAttributeItem item) 20 | { 21 | if (attrs == null) 22 | attrs = new List(); 23 | attrs.Add(item); 24 | } 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | public void Add(string name, string value) 31 | { 32 | var item = new UserExtensionAttributeItem(name, value); 33 | this.Add(item); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/UserExtensionAttributeItem.cs: -------------------------------------------------------------------------------- 1 | namespace Api.Weixin.Qy 2 | { 3 | /// 4 | /// 5 | /// 6 | public class UserExtensionAttributeItem 7 | { 8 | /// 9 | /// 10 | /// 11 | public UserExtensionAttributeItem() { } 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 17 | public UserExtensionAttributeItem(string name, string value) 18 | { 19 | this.name = name; 20 | this.value = value; 21 | } 22 | /// 23 | /// 24 | /// 25 | public string name { get; set; } 26 | /// 27 | /// 28 | /// 29 | public string value { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/UserInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Api.Weixin.Qy 2 | { 3 | /// 4 | /// 成员信息 5 | /// 6 | public class UserInfo : UserSimple 7 | { 8 | /// 9 | /// 职位信息。长度为0~64个字符 10 | /// 11 | public string position { get; set; } 12 | /// 13 | /// 手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空 14 | /// 15 | public string mobile { get; set; } 16 | /// 17 | /// 性别。gender=0表示男,=1表示女。默认gender=0 18 | /// 19 | public int gender { get; set; } 20 | /// 21 | /// 办公电话。长度为0~64个字符 22 | /// 23 | public string tel { get; set; } 24 | /// 25 | /// 邮箱。长度为0~64个字符。企业内必须唯一 26 | /// 27 | public string email { get; set; } 28 | /// 29 | /// 微信号。企业内必须唯一 30 | /// 31 | public string weixinid { get; set; } 32 | /// 33 | /// 头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可 34 | /// 35 | public string avatar { get; set; } 36 | /// 37 | /// 关注状态: 1=已关注,2=已冻结,4=未关注 38 | /// 39 | public int status { get; set; } 40 | /// 41 | /// 扩展属性 42 | /// 43 | public UserExtensionAttribute extattr { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/Models/UserSimple.cs: -------------------------------------------------------------------------------- 1 | namespace Api.Weixin.Qy 2 | { 3 | /// 4 | /// 用户简单属性 5 | /// 6 | public class UserSimple 7 | { 8 | /// 9 | /// 员工UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字符 10 | /// 11 | public string userid { get; set; } 12 | /// 13 | /// 成员名称。长度为1~64个字符 14 | /// 15 | public string name { get; set; } 16 | /// 17 | /// 18 | /// 19 | public int[] department { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /Api.Weixin.Qy/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Api.Weixin.Qy")] 9 | [assembly: AssemblyDescription("微信企业号API")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Api.Weixin.Qy")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("fc777c90-d82b-473e-88b2-96d8e1b6bbfb")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.1.2.4")] 36 | [assembly: AssemblyFileVersion("1.1.2.4")] 37 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetAgentRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取企业号应用所需参数 7 | /// 8 | public class GetAgentRequest : IRequest 9 | { 10 | /// 11 | /// 应用套件id 12 | /// 13 | public string suite_id { get; set; } 14 | /// 15 | /// 授权方corpid 16 | /// 17 | public string auth_corpid { get; set; } 18 | /// 19 | /// 永久授权码,从get_permanent_code接口中获取 20 | /// 21 | public string permanent_code { get; set; } 22 | /// 23 | /// 授权方应用id 24 | /// 25 | public string agentid { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetAuthInfoRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取企业号的授权信息所需参数 7 | /// 8 | public class GetAuthInfoRequest : IRequest 9 | { 10 | /// 11 | /// 应用套件id 12 | /// 13 | public string suite_id { get; set; } 14 | /// 15 | /// 授权方corpid 16 | /// 17 | public string auth_corpid { get; set; } 18 | /// 19 | /// 永久授权码,通过get_permanent_code获取 20 | /// 21 | public string permanent_code { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetAuthInfoResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取企业号的授权信息 返回信息 7 | /// 8 | public class GetAuthInfoResult : JsonResult 9 | { 10 | /// 11 | /// 授权方企业信息 12 | /// 13 | public AuthCorpInfo corp_info { get; set; } 14 | /// 15 | /// 授权信息 16 | /// 17 | public AuthInfo auth_info { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetCorpTokenRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取企业号access_token 7 | /// 8 | public class GetCorpTokenRequest : IRequest 9 | { 10 | /// 11 | /// 应用套件id 12 | /// 13 | public string suite_id { get; set; } 14 | /// 15 | /// 授权方corpid 16 | /// 17 | public string auth_corpid { get; set; } 18 | /// 19 | /// 永久授权码,通过get_permanent_code获取 20 | /// 21 | public string permanent_code { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetCorpTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取企业号access_token 7 | /// 8 | public class GetCorpTokenResult : JsonResult 9 | { 10 | /// 11 | /// 授权方(企业)access_token 12 | /// 13 | public string access_token { get; set; } 14 | /// 15 | /// 授权方(企业)access_token超时时间 16 | /// 17 | public int expires_in { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetPermanentCodeRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取企业号的永久授权码,所需参数 7 | /// 8 | public class GetPermanentCodeRequest : IRequest 9 | { 10 | /// 11 | /// 应用套件id 12 | /// 13 | public string suite_id { get; set; } 14 | /// 15 | /// 临时授权码会在授权成功时附加在redirect_uri中跳转回应用提供商网站。 16 | /// 17 | public string auth_code { get; set; } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetPermanentCodeResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Api.Core; 3 | 4 | namespace Api.Weixin.Qy.ThirdAuth 5 | { 6 | /// 7 | /// 获取企业号的永久授权码,返回信息 8 | /// 9 | [Serializable] 10 | public class GetPermanentCodeResult : JsonResult 11 | { 12 | /// 13 | /// 授权方(企业)access_token 14 | /// 15 | public string access_token { get; set; } 16 | /// 17 | /// 授权方(企业)access_token超时时间 18 | /// 19 | public int expires_in { get; set; } 20 | /// 21 | /// 企业号永久授权码 22 | /// 23 | public string permanent_code { get; set; } 24 | /// 25 | /// 授权方企业信息 26 | /// 27 | public AuthCorpInfo auth_corp_info { get; set; } 28 | /// 29 | /// 授权信息 30 | /// 31 | public AuthInfo auth_info { get; set; } 32 | /// 33 | /// 授权管理员的信息 34 | /// 35 | public AuthUserInfo auth_user_info { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetPreAuthCodeReqeust.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Api.Weixin.Qy.ThirdAuth 5 | { 6 | /// 7 | /// 获取预授权码 所需参数 8 | /// 9 | public class GetPreAuthCodeReqeust : IRequest 10 | { 11 | /// 12 | /// 应用套件id 13 | /// 14 | public string suite_id { get; set; } 15 | /// 16 | /// 应用id,本参数选填,表示用户能对本套件内的哪些应用授权,不填时默认用户有全部授权权限 17 | /// e.g.[id1,id2,id3] 18 | /// 19 | public List appid { get; set; } 20 | 21 | /// 22 | /// 设置appid 23 | /// 24 | /// 25 | public void SetAppId(params int[] appIds) 26 | { 27 | if (appid == null) 28 | appid = new List(); 29 | appid.AddRange(appIds); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetPreAuthCodeResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取预授权码 返回信息 7 | /// 8 | public class GetPreAuthCodeResult : JsonResult 9 | { 10 | private string _pre_auth_code; 11 | /// 12 | /// 预授权码 13 | /// 14 | public string pre_auth_code 15 | { 16 | get { return _pre_auth_code; } 17 | set { _pre_auth_code = value; } 18 | } 19 | /// 20 | /// 有效期 21 | /// 22 | public int expires_in { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetSuiteTokenRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取应用套件令牌所需参数 7 | /// 8 | public class GetSuiteTokenRequest : IRequest 9 | { 10 | /// 11 | /// 应用套件id 12 | /// 13 | public string suite_id { get; set; } 14 | /// 15 | /// 应用套件secret 16 | /// 17 | public string suite_secret { get; set; } 18 | /// 19 | /// 微信后台推送的ticket 20 | /// 21 | public string suite_ticket { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/GetSuiteTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 获取应用套件令牌,返回信息 7 | /// 8 | public class GetSuiteTokenResult : JsonResult 9 | { 10 | /// 11 | /// 应用套件access_token 12 | /// 13 | public string suite_access_token { get; set; } 14 | /// 15 | /// 有效期 16 | /// 17 | public int expires_in { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/SetAgentRequest.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 设置企业号应用 7 | /// 8 | public class SetAgentRequest : IRequest 9 | { 10 | /// 11 | /// 应用套件id 12 | /// 13 | public string suite_id { get; set; } 14 | /// 15 | /// 授权方corpid 16 | /// 17 | public string auth_corpid { get; set; } 18 | /// 19 | /// 永久授权码,从get_permanent_code接口中获取 20 | /// 21 | public string permanent_code { get; set; } 22 | /// 23 | /// 要设置的企业应用的信息 24 | /// 25 | public SetAgentInfo agent { get; set; } 26 | } 27 | 28 | /// 29 | /// 要设置的企业应用的信息 30 | /// 31 | public class SetAgentInfo 32 | { 33 | /// 34 | /// 企业应用的id 35 | /// 36 | public int agentid { get; set; } 37 | /// 38 | /// 企业应用是否打开地理位置上报 0:不上报;1:进入会话上报;2:持续上报 39 | /// 40 | public int? report_location_flag { get; set; } 41 | /// 42 | /// 企业应用头像的mediaid,通过多媒体接口上传图片获得mediaid,上传后会自动裁剪成方形和圆形两个头像 43 | /// 44 | public string logo_mediaid { get; set; } 45 | /// 46 | /// 企业应用名称 47 | /// 48 | public string name { get; set; } 49 | /// 50 | /// 企业应用详情 51 | /// 52 | public string description { get; set; } 53 | /// 54 | /// 企业应用可信域名 55 | /// 56 | public string redirect_domain { get; set; } 57 | /// 58 | /// 是否接收用户变更通知。0:不接收;1:接收 59 | /// 60 | public int isreportuser { get; set; } 61 | /// 62 | /// 是否上报用户进入应用事件。0:不接收;1:接收 63 | /// 64 | public int isreportenter { get; set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/SetAgentResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 7 | /// 8 | public class SetAgentResult : JsonResult 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/SetSessionInfoRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Qy.ThirdAuth.Messages 7 | { 8 | class SetSessionInfoRequest 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Messages/SyncGetPageResult.cs: -------------------------------------------------------------------------------- 1 | using Api.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy.ThirdAuth 8 | { 9 | /// 10 | /// 11 | /// 12 | public class SyncGetPageResult : JsonResult 13 | { 14 | /// 15 | /// 16 | /// 17 | public int next_seq { get; set; } 18 | /// 19 | /// 20 | /// 21 | public int next_offset { get; set; } 22 | /// 23 | /// 24 | /// 25 | public int is_last { get; set; } 26 | /// 27 | /// 数据数组 28 | /// 29 | public IList data { get; set; } 30 | 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Models/AuthAgent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy.ThirdAuth 8 | { 9 | /// 10 | /// 授权的应用信息,用于授权应用 11 | /// 12 | [Serializable] 13 | public class AuthAgent 14 | { 15 | /// 16 | /// 授权方应用id 17 | /// 18 | public int agentid { get; set; } 19 | /// 20 | /// 授权方应用名字 21 | /// 22 | public string name { get; set; } 23 | /// 24 | /// 授权方应用方形头像 25 | /// 26 | public string square_logo_url { get; set; } 27 | /// 28 | /// 授权方应用圆形头像 29 | /// 30 | public string round_logo_url { get; set; } 31 | /// 32 | /// 服务商套件中的对应应用id 33 | /// 34 | public int appid { get; set; } 35 | /// 36 | /// 授权方应用敏感权限组,目前仅有get_location,表示是否有权限设置应用获取地理位置的开关 37 | /// 38 | public string[] api_group { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Models/AuthCorpInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Api.Weixin.Qy.ThirdAuth 4 | { 5 | /// 6 | /// 授权方企业信息 7 | /// 8 | [Serializable] 9 | public class AuthCorpInfo 10 | { 11 | /// 12 | /// 授权方企业号id 13 | /// 14 | public string corpid { get; set; } 15 | /// 16 | /// 授权方企业号名称 17 | /// 18 | public string corp_name { get; set; } 19 | /// 20 | /// 授权方企业号类型,认证号:verified, 注册号:unverified,体验号:test 21 | /// 22 | public string corp_type { get; set; } 23 | /// 24 | /// 授权方企业号圆形头像 25 | /// 26 | public string corp_round_logo_url { get; set; } 27 | /// 28 | /// 授权方企业号方形头像 29 | /// 30 | public string corp_square_logo_url { get; set; } 31 | /// 32 | /// 授权方企业号用户规模 33 | /// 34 | public int corp_user_max { get; set; } 35 | /// 36 | /// 授权方企业号应用规模 37 | /// 38 | public int corp_agent_max { get; set; } 39 | /// 40 | /// 所绑定的企业号主体名称 41 | /// 42 | public string corp_full_name { get; set; } 43 | /// 44 | /// 认证到期时间 45 | /// 46 | public long verified_end_time { get; set; } 47 | /// 48 | /// 企业类型,1. 企业; 2. 政府以及事业单位; 3. 其他组织, 4.团队号 49 | /// 50 | public string subject_type { get; set; } 51 | /// 52 | /// 授权方企业号二维码 53 | /// 54 | public string corp_wxqrcode { get; set; } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Models/AuthDepartment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Qy.ThirdAuth 7 | { 8 | /// 9 | /// 授权的通讯录部门,用于授权应用 10 | /// 11 | [Serializable] 12 | public class AuthDepartment 13 | { 14 | /// 15 | /// 部门ID 16 | /// 17 | public int id { get; set; } 18 | /// 19 | /// 部门名称 20 | /// 21 | public string name { get; set; } 22 | /// 23 | /// 父级部门ID 24 | /// 25 | public int parentid { get; set; } 26 | /// 27 | /// 是否具有该部门的写权限 28 | /// 29 | public bool writable { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Models/AuthInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | 7 | namespace Api.Weixin.Qy.ThirdAuth 8 | { 9 | /// 10 | /// 授权信息,用于授权 11 | /// 12 | [Serializable] 13 | public class AuthInfo 14 | { 15 | /// 16 | /// 授权的应用信息 17 | /// 18 | public List agent { get; set; } 19 | /// 20 | /// 授权的通讯录部门 21 | /// 22 | public List department { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/ThirdAuth/Models/AuthUserInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Api.Weixin.Qy.ThirdAuth 7 | { 8 | /// 9 | /// 授权管理员的信息 10 | /// 11 | public class AuthUserInfo 12 | { 13 | /// 14 | /// 授权管理员的邮箱,可能为空(管理员通讯录中邮箱被清空) 15 | /// 16 | public string email { get; set; } 17 | /// 18 | /// 授权管理员的手机号,可能为空(管理员在通讯录中未设置手机号) 19 | /// 20 | public string mobile { get; set; } 21 | /// 22 | /// 授权管理员的userid,可能为空(管理员不在通讯录中) 23 | /// 24 | public string userid { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Api.Weixin.Qy/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jaryway 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 这是一个基于微信企业号、公众号、钉钉、蓝信开发文档开发的Api类库,用于调用各个平台的接口。 --------------------------------------------------------------------------------