23
This commit is contained in:
17
MyCode.Project.OutSideService/IDingDingService.cs
Normal file
17
MyCode.Project.OutSideService/IDingDingService.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCode.Project.OutSideService
|
||||
{
|
||||
public interface IDingDingService
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
void SendMsg(string content);
|
||||
}
|
||||
}
|
||||
57
MyCode.Project.OutSideService/IEnterpriseWechatService.cs
Normal file
57
MyCode.Project.OutSideService/IEnterpriseWechatService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using MyCode.Project.Domain.Message.Response.EnterpriseWechat;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCode.Project.OutSideService
|
||||
{
|
||||
public interface IEnterpriseWechatService
|
||||
{
|
||||
/// <summary>
|
||||
/// 得到AccessToken,有效期7200秒
|
||||
/// </summary>
|
||||
/// <param name="corpId">企业id</param>
|
||||
/// <param name="secret"></param>
|
||||
/// <returns></returns>
|
||||
string GetAccessToken(string corpId, string secret);
|
||||
|
||||
/// <summary>
|
||||
/// 取得通讯录的部门列表
|
||||
/// </summary>
|
||||
/// <param name="accessToken"></param>
|
||||
/// <returns></returns>
|
||||
List<DepartmentHasChild> GetDepartmentList(string accessToken, string corpId = "", string secret = "");
|
||||
|
||||
/// <summary>
|
||||
/// 得到部门的员工列表
|
||||
/// </summary>
|
||||
/// <param name="accessToken">通讯录的token</param>
|
||||
/// <param name="departmentId">部门id</param>
|
||||
/// <param name="fetch_child">是否递归获取子部门下面的成员:1-递归获取,0-只获取本部门</param>
|
||||
/// <returns></returns>
|
||||
List<DepartmentMemberInfo> GetDepartmentMemberList(string accessToken, long departmentId, string corpId = "", string secret = "", int fetch_child = 0);
|
||||
|
||||
/// <summary>
|
||||
/// 获取员工信息
|
||||
/// </summary>
|
||||
/// <param name="userId">员工id</param>
|
||||
/// <returns></returns>
|
||||
EnterpriseEmployeeInfo GetEmployeeInfo(string userId, string corpId, string secret);
|
||||
|
||||
/// <summary>
|
||||
/// userid转openid
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="corpId"></param>
|
||||
/// <param name="secret"></param>
|
||||
/// <returns></returns>
|
||||
UserIdChangeOpenIdResp GetOpenidByUserid(string userId, string corpId = "", string secret = "");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using MyCode.Project.Domain.Config;
|
||||
using MyCode.Project.Infrastructure.Common;
|
||||
using MyCode.Project.Infrastructure.WebPost;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCode.Project.OutSideService.Implementation
|
||||
{
|
||||
public class DingDingService:IDingDingService
|
||||
{
|
||||
public DingDingService()
|
||||
{
|
||||
}
|
||||
|
||||
#region SendMsg(发送信息)
|
||||
public void SendMsg(string content)
|
||||
{
|
||||
var url = SystemConfig.DingDingApiUrl;
|
||||
|
||||
WebUtils webUtils = new WebUtils();
|
||||
|
||||
var jsonObject = new { msgtype = "text", text = new { content = SystemConfig.DingDingTxt+ content } };
|
||||
|
||||
var jsonStr = JsonHelper.ToJson(jsonObject);
|
||||
|
||||
var result = webUtils.DoPostJson(url, jsonStr);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,474 @@
|
||||
using MyCode.Project.Domain.Message.Response.EnterpriseWechat;
|
||||
using MyCode.Project.Domain.Message.Response.Wechat;
|
||||
using MyCode.Project.Infrastructure.Cache;
|
||||
using MyCode.Project.Infrastructure.Common;
|
||||
using MyCode.Project.Infrastructure.Constant;
|
||||
using MyCode.Project.Infrastructure.Exceptions;
|
||||
using MyCode.Project.Infrastructure.WebPost;
|
||||
using Senparc.CO2NET.Extensions;
|
||||
using Senparc.Weixin;
|
||||
using Senparc.Weixin.MP.Entities;
|
||||
using Senparc.Weixin.MP.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace MyCode.Project.OutSideService.Implementation
|
||||
{
|
||||
public class EnterpriseWechatService : IEnterpriseWechatService
|
||||
{
|
||||
private readonly string apiUrl = "https://qyapi.weixin.qq.com/";
|
||||
|
||||
|
||||
private readonly IMyCodeCacheService _myCodeCacheService;
|
||||
|
||||
public EnterpriseWechatService(
|
||||
IMyCodeCacheService myCodeCacheService
|
||||
)
|
||||
{
|
||||
_myCodeCacheService = myCodeCacheService;
|
||||
|
||||
}
|
||||
|
||||
#region 基础辅助
|
||||
|
||||
#region Get(进一步封装Get方法)
|
||||
/// <summary>
|
||||
/// 进一步封装Get方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
private T Get<T>(string url) where T : BaseEnterpriseResp
|
||||
{
|
||||
var webUtils = new WebUtils();
|
||||
|
||||
var resp = webUtils.DoGet<T>(url, null);
|
||||
|
||||
resp.CheckResult();
|
||||
|
||||
return resp;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToDepartmentHasChild(部门转成含有子节点的结构)
|
||||
public List<DepartmentHasChild> ToDepartmentHasChild(List<DepartmentInfo> listDepartmentInfo)
|
||||
{
|
||||
if (listDepartmentInfo == null || listDepartmentInfo.Count == 0) { return null; }
|
||||
|
||||
//公司节点
|
||||
var rootList = listDepartmentInfo.FindAll(p => p.Parentid == 0);
|
||||
|
||||
var returnList = new List<DepartmentHasChild>();
|
||||
|
||||
//子节点
|
||||
foreach (var root in rootList)
|
||||
{
|
||||
var item = new DepartmentHasChild
|
||||
{
|
||||
Id = root.Id,
|
||||
Name = root.Name,
|
||||
Parentid = root.Parentid
|
||||
};
|
||||
|
||||
item.ListChild = GetDepartmentChild(listDepartmentInfo, root.Id);
|
||||
|
||||
returnList.Add(item);
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetDepartmentChild(得到部门子节点)
|
||||
/// <summary>
|
||||
/// 得到子节点
|
||||
/// </summary>
|
||||
/// <param name="listDepartmentInfo"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
public List<DepartmentHasChild> GetDepartmentChild(List<DepartmentInfo> listDepartmentInfo, int parentId)
|
||||
{
|
||||
var list = listDepartmentInfo.FindAll(p => p.Parentid == parentId);
|
||||
|
||||
var returnList = new List<DepartmentHasChild>();
|
||||
|
||||
if (list == null || list.Count == 0) { return new List<DepartmentHasChild> { }; }
|
||||
|
||||
foreach (var child in list)
|
||||
{
|
||||
var item = new DepartmentHasChild
|
||||
{
|
||||
Id = child.Id,
|
||||
Name = child.Name,
|
||||
Parentid = child.Parentid,
|
||||
Order = child.Order
|
||||
};
|
||||
item.ListChild = GetDepartmentChild(listDepartmentInfo, child.Id);
|
||||
|
||||
returnList.Add(item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return returnList;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetAccessToken(得到AccessToken,有效期7200秒)
|
||||
/// <summary>
|
||||
/// 得到AccessToken,有效期7200秒
|
||||
/// </summary>
|
||||
/// <param name="corpId">企业id</param>
|
||||
/// <param name="secret"></param>
|
||||
/// <returns></returns>
|
||||
public string GetAccessToken(string corpId, string secret)
|
||||
{
|
||||
var cacheKey = $"{CacheKey.EnterpriseWechatTokenKey}{corpId}{secret}";
|
||||
|
||||
if (_myCodeCacheService.Exists(cacheKey))
|
||||
{
|
||||
return _myCodeCacheService.Get<string>(cacheKey);
|
||||
}
|
||||
var url = $"{apiUrl}cgi-bin/gettoken?corpid={corpId}&corpsecret={secret}";
|
||||
|
||||
var resp = Get<GetTokenResp>(url);
|
||||
|
||||
var token = resp.Access_token;
|
||||
|
||||
_myCodeCacheService.Set(cacheKey, token, new TimeSpan(1, 0, 0));
|
||||
|
||||
return token;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetTicket(获取企业微信Ticket)
|
||||
/// <summary>
|
||||
/// 获取企业微信Ticket
|
||||
/// </summary>
|
||||
/// <param name="accessToken">对应的应用的token</param>
|
||||
/// <returns></returns>
|
||||
private string GetTicket(string accessToken)
|
||||
{
|
||||
var cacheKey = $"{accessToken}";
|
||||
|
||||
if (_myCodeCacheService.Exists(cacheKey))
|
||||
{
|
||||
return _myCodeCacheService.Get<string>(cacheKey);
|
||||
}
|
||||
|
||||
var url = string.Format(apiUrl + "cgi-bin/get_jsapi_ticket?access_token={0}", accessToken.AsUrlData());
|
||||
|
||||
JsApiTicketResult result = Senparc.CO2NET.HttpUtility.Get.GetJson<JsApiTicketResult>(url);
|
||||
|
||||
if (result.errcode != ReturnCode.请求成功) { throw new BaseException(result.ToJson()); }
|
||||
|
||||
_myCodeCacheService.Set(cacheKey, result.ticket, new TimeSpan(1, 0, 0));
|
||||
|
||||
|
||||
return result.ticket;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetApplicationTicket(应用的jsapi_ticket)
|
||||
/// <summary>
|
||||
/// 应用的jsapi_ticket
|
||||
/// </summary>
|
||||
/// <param name="accessToken">对应的应用的token</param>
|
||||
/// <returns></returns>
|
||||
private string GetApplicationTicket(string accessToken)
|
||||
{
|
||||
var cacheKey = $"{accessToken}2";
|
||||
|
||||
if (_myCodeCacheService.Exists(cacheKey))
|
||||
{
|
||||
return _myCodeCacheService.Get<string>(cacheKey);
|
||||
}
|
||||
|
||||
var url = string.Format(apiUrl + "cgi-bin/ticket/get?access_token={0}&type=agent_config", accessToken.AsUrlData());
|
||||
|
||||
JsApiTicketResult result = Senparc.CO2NET.HttpUtility.Get.GetJson<JsApiTicketResult>(url);
|
||||
|
||||
if (result.errcode != ReturnCode.请求成功) { throw new BaseException(result.ToJson()); }
|
||||
|
||||
_myCodeCacheService.Set(cacheKey, result.ticket, new TimeSpan(1, 0, 0));
|
||||
|
||||
|
||||
return result.ticket;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetJsSdk(取得企业微信JsSdk相关参数值)
|
||||
/// <summary>
|
||||
/// 取得微信JsSdk相关参数值
|
||||
/// </summary>
|
||||
/// <param name="appId">微信应用ID</param>
|
||||
/// <param name="ticket">JsTicket</param>
|
||||
/// <param name="url">需要授权Url地址</param>
|
||||
/// <returns></returns>
|
||||
private JsSdkResp GetJsSdk(string appId, string ticket, string url)
|
||||
{
|
||||
var decodeUrl = HttpUtility.UrlDecode(url);
|
||||
string timeStamp = JSSDKHelper.GetTimestamp();
|
||||
string nonceStr = JSSDKHelper.GetNoncestr();
|
||||
|
||||
string signature = "";
|
||||
var paySignReqHandler = new Senparc.Weixin.TenPay.V2.RequestHandler(null);
|
||||
|
||||
paySignReqHandler.SetParameter("jsapi_ticket", ticket);
|
||||
paySignReqHandler.SetParameter("noncestr", nonceStr);
|
||||
paySignReqHandler.SetParameter("timestamp", timeStamp);
|
||||
paySignReqHandler.SetParameter("url", decodeUrl);
|
||||
|
||||
signature = paySignReqHandler.CreateSHA1Sign();
|
||||
|
||||
return new JsSdkResp
|
||||
{
|
||||
AppId = appId,
|
||||
Timestamp = timeStamp,
|
||||
NonceStr = nonceStr,
|
||||
Signature = signature
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取企业微信的JS-SDK权限验证的签名Signature
|
||||
/// <summary>
|
||||
/// 获取企业微信的JS-SDK权限验证的签名Signature
|
||||
/// </summary>
|
||||
/// <param name="jsapi_ticket">jsapi_ticket</param>
|
||||
/// <param name="noncestr">随机字符串(必须与wx.config中的nonceStr相同)</param>
|
||||
/// <param name="timestamp">时间戳(必须与wx.config中的timestamp相同)</param>
|
||||
/// <param name="url">当前网页的URL,不包含#及其后面部分(必须是调用JS接口页面的完整URL)</param>
|
||||
/// <returns></returns>
|
||||
private string GetSignature(string jsapi_ticket, string noncestr, long timestamp, string url)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("jsapi_ticket=").Append(jsapi_ticket).Append("&")
|
||||
.Append("noncestr=").Append(noncestr).Append("&")
|
||||
.Append("timestamp=").Append(timestamp).Append("&")
|
||||
.Append("url=").Append(url.IndexOf("#") >= 0 ? url.Substring(0, url.IndexOf("#")) : url);
|
||||
string dddd = sb.ToString();
|
||||
LogHelper.Info("Signature: " + dddd);
|
||||
return Senparc.CO2NET.Helpers.EncryptHelper.GetSha1(sb.ToString()).ToLower();
|
||||
}
|
||||
#endregion
|
||||
|
||||
//#region GetJsSdk(取得企业微信某个应用的JsSdk相关参数值)
|
||||
///// <summary>
|
||||
///// 取得企业微信某个应用的JsSdk相关参数值
|
||||
///// </summary>
|
||||
///// <param name="url"></param>
|
||||
///// <param name="tokenType">第一步传 1 第二步传2</param>
|
||||
///// <returns></returns>
|
||||
//public EnterpriseWechatJsSdkResp GetJsSdk(string url, int tokenType = 1)
|
||||
//{
|
||||
|
||||
// EnterpriseWechatJsSdkResp result = new EnterpriseWechatJsSdkResp();
|
||||
|
||||
|
||||
|
||||
// string corpId = companyConfig.Corpid;
|
||||
// string agentId = companyConfig.CustomerAgentidId.Replace("\r\n", "");
|
||||
// string secret = companyConfig.CustomerDetailSecret;
|
||||
// string ticket = "";
|
||||
|
||||
// string token = GetAccessToken(corpId, secret);
|
||||
// long timeStamp = 0;
|
||||
// string nonceStr = "";
|
||||
|
||||
// if (tokenType == 1)
|
||||
// {
|
||||
// ticket = GetTicket(token);
|
||||
// timeStamp = long.Parse(JSSDKHelper.GetTimestamp());
|
||||
// nonceStr = JSSDKHelper.GetNoncestr();
|
||||
// }
|
||||
// else if (tokenType == 2)
|
||||
// {
|
||||
// result = _myCodeCacheService.Get<EnterpriseWechatJsSdkResp>(companyConfig.Corpid + "1");
|
||||
// ticket = GetApplicationTicket(token);
|
||||
// timeStamp = long.Parse(result.Timestamp);
|
||||
// nonceStr = result.NonceStr;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// //var decodeUrl = HttpUtility.UrlDecode(url);
|
||||
|
||||
// string signature = GetSignature(ticket, nonceStr, timeStamp, url);
|
||||
// result.CorpId = corpId;
|
||||
// result.AgentId = agentId;
|
||||
// result.NonceStr = nonceStr;
|
||||
// result.Signature = signature;
|
||||
// result.Timestamp = timeStamp.ToString();
|
||||
// //LogHelper.Info("result:");
|
||||
// //LogHelper.Info(result);
|
||||
// _myCodeCacheService.Set(cacheKey, result, new TimeSpan(1, 0, 0));
|
||||
|
||||
// return result;
|
||||
|
||||
//}
|
||||
//#endregion
|
||||
|
||||
#region GetDepartmentList(得到部门列表)
|
||||
/// <summary>
|
||||
/// 取得通讯录的部门列表,使用通讯录Token
|
||||
/// </summary>
|
||||
/// <param name="accessToken">Token</param>
|
||||
/// <returns></returns>
|
||||
public List<DepartmentHasChild> GetDepartmentList(string accessToken, string corpId, string secret)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
accessToken = GetAccessToken(corpId, secret);
|
||||
}
|
||||
var url = $"{apiUrl}cgi-bin/department/list?access_token={accessToken}";
|
||||
|
||||
var resp = Get<DepartmentResp>(url);
|
||||
|
||||
if (resp.Department == null || resp.Department.Count == 0) { return new List<DepartmentHasChild> { }; }
|
||||
|
||||
return GetDepartmentChild(resp.Department, 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetDepartmentMemberList(得到部门的员工列表)
|
||||
/// <summary>
|
||||
/// 得到部门的员工列表
|
||||
/// </summary>
|
||||
/// <param name="accessToken">通讯录的token</param>
|
||||
/// <param name="departmentId">部门id</param>
|
||||
/// <param name="fetch_child">是否递归获取子部门下面的成员:1-递归获取,0-只获取本部门</param>
|
||||
/// <returns></returns>
|
||||
public List<DepartmentMemberInfo> GetDepartmentMemberList(string accessToken, long departmentId, string corpId, string secret, int fetch_child = 0)
|
||||
{
|
||||
//if (departmentId == 0) { throw new BaseException("部门id不能为0"); }
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
accessToken = GetAccessToken(corpId, secret);
|
||||
}
|
||||
var url = $"{apiUrl}cgi-bin/user/simplelist?access_token={accessToken}&department_id={departmentId}&fetch_child={fetch_child}";//是否递归获取子部门下面的成员:1-递归获取,0-只获取本部门
|
||||
|
||||
var resp = Get<DepartmentMemberInfoResp>(url);
|
||||
|
||||
if (resp.Userlist == null || resp.Userlist.Count == 0) { return new List<DepartmentMemberInfo> { }; }
|
||||
|
||||
return resp.Userlist;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetEmployeeInfo(获取员工信息)
|
||||
/// <summary>
|
||||
/// 获取员工信息
|
||||
/// </summary>
|
||||
/// <param name="userId">员工id</param>
|
||||
/// <returns></returns>
|
||||
public EnterpriseEmployeeInfo GetEmployeeInfo(string userId, string corpId, string secret)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(userId)) { throw new BaseException("员工id不能为空"); }
|
||||
var accessToken = GetAccessToken(corpId, secret);
|
||||
var url = $"{apiUrl}/cgi-bin/user/get?access_token={accessToken}&userid={userId}";
|
||||
var webUtils = new WebUtils();
|
||||
var resp = webUtils.DoGet<EnterpriseEmployeeInfo>(url, null);
|
||||
return resp;
|
||||
}
|
||||
#endregion
|
||||
//#region GetLoginUserInfo(获取登录用户信息)
|
||||
///// <summary>
|
||||
///// 获取登录用户信息
|
||||
///// </summary>
|
||||
///// <param name="code"></param>
|
||||
///// <param name="corpId"></param>
|
||||
///// <param name="secret">自建应用secret</param>
|
||||
///// <returns></returns>
|
||||
//public UserInfoResp GetLoginUserInfo(string code, string corpId = "", string secret = "")
|
||||
//{
|
||||
// var accessToken = GetAccessToken(corpId, secret);
|
||||
// var url = $"{apiUrl}/cgi-bin/user/getuserinfo?access_token={accessToken}&code={code}";
|
||||
// var result = Get<UserInfoResp>(url);
|
||||
// return result;
|
||||
//}
|
||||
//#endregion
|
||||
|
||||
#region 从url读取内容到内存Stream流中
|
||||
/// <summary>
|
||||
/// 从url读取内容到内存Stream流中
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public Stream DownLoadFielToStream(string url)
|
||||
{
|
||||
var wreq = HttpWebRequest.Create(url) as HttpWebRequest;
|
||||
HttpWebResponse response = wreq.GetResponse() as HttpWebResponse;
|
||||
MemoryStream ms = null;
|
||||
using (var stream = response.GetResponseStream())
|
||||
{
|
||||
Byte[] buffer = new Byte[response.ContentLength];
|
||||
int offset = 0, actuallyRead = 0;
|
||||
do
|
||||
{
|
||||
actuallyRead = stream.Read(buffer, offset, buffer.Length - offset);
|
||||
offset += actuallyRead;
|
||||
}
|
||||
while (actuallyRead > 0);
|
||||
ms = new MemoryStream(buffer);
|
||||
}
|
||||
response.Close();
|
||||
return ms;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
//#region openid转userid
|
||||
///// <summary>
|
||||
///// openid转userid
|
||||
///// </summary>
|
||||
///// <param name="openid"></param>
|
||||
///// <param name="corpId"></param>
|
||||
///// <param name="secret">通讯录secret</param>
|
||||
///// <returns></returns>
|
||||
//public OpenIdChangeUseridResp GetUseridByOpenid(string openid, string corpId = "", string secret = "")
|
||||
//{
|
||||
// var accessToken = GetAccessToken(corpId, secret);
|
||||
// var url = $"{apiUrl}cgi-bin/user/convert_to_userid?access_token={accessToken}";
|
||||
// var webUtils = new WebUtils();
|
||||
// var resp = webUtils.DoGet<OpenIdChangeUseridResp>(url, null);
|
||||
// return resp;
|
||||
//}
|
||||
//#endregion
|
||||
|
||||
|
||||
#region userid转openid
|
||||
/// <summary>
|
||||
/// userid转openid
|
||||
/// </summary>
|
||||
/// <param name="openid"></param>
|
||||
/// <param name="corpId"></param>
|
||||
/// <param name="secret">通讯录secret</param>
|
||||
/// <returns></returns>
|
||||
public UserIdChangeOpenIdResp GetOpenidByUserid(string userId, string corpId = "", string secret = "")
|
||||
{
|
||||
var accessToken = GetAccessToken(corpId, secret);
|
||||
var url = $"{apiUrl}cgi-bin/user/convert_to_openid?access_token={accessToken}";
|
||||
string json = $@"{{
|
||||
""userid"": ""{userId}""
|
||||
}}";
|
||||
var webUtils = new WebUtils();
|
||||
var resp = webUtils.DoPostJson(url, json);
|
||||
UserIdChangeOpenIdResp resut = JsonHelper.ToObject<UserIdChangeOpenIdResp>(resp);
|
||||
return resut;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BC7E3726-8F90-4CA9-9269-731987907051}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MyCode.Project.OutSideService</RootNamespace>
|
||||
<AssemblyName>MyCode.Project.OutSideService</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\Microsoft.Practices.Unity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Unity.Interception, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\Microsoft.Practices.Unity.Interception.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Qiniu">
|
||||
<HintPath>..\Lib\Qiniu.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.CO2NET, Version=0.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Senparc.CO2NET.0.4.4\lib\net45\Senparc.CO2NET.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.CO2NET.APM, Version=0.2.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Senparc.CO2NET.APM.0.2.2\lib\net45\Senparc.CO2NET.APM.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.NeuChar, Version=0.5.5.2, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Senparc.NeuChar.0.5.5.2\lib\net45\Senparc.NeuChar.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.Weixin, Version=6.3.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Senparc.Weixin.6.3.4\lib\net45\Senparc.Weixin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.Weixin.MP, Version=16.6.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Senparc.Weixin.MP.16.6.0\lib\net45\Senparc.Weixin.MP.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.Weixin.TenPay, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Senparc.Weixin.TenPay.1.1.2\lib\net45\Senparc.Weixin.TenPay.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Senparc.Weixin.WxOpen, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\Senparc.Weixin.WxOpen.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IEnterpriseWechatService.cs" />
|
||||
<Compile Include="Implementation\EnterpriseWechatService.cs" />
|
||||
<Compile Include="IDingDingService.cs" />
|
||||
<Compile Include="Implementation\DingDingService.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MyCode.Project.Domain\MyCode.Project.Domain.csproj">
|
||||
<Project>{83c7dd85-ca0f-4250-a4ad-b31dd56b14f1}</Project>
|
||||
<Name>MyCode.Project.Domain</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\MyCode.Project.Infrastructure\MyCode.Project.Infrastructure.csproj">
|
||||
<Project>{b047e3d9-bc3b-4926-954a-0085ad847e75}</Project>
|
||||
<Name>MyCode.Project.Infrastructure</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
36
MyCode.Project.OutSideService/Properties/AssemblyInfo.cs
Normal file
36
MyCode.Project.OutSideService/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("MyCode.Project.OutSideService")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("CHINA")]
|
||||
[assembly: AssemblyProduct("MyCode.Project.OutSideService")]
|
||||
[assembly: AssemblyCopyright("Copyright © CHINA 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("bc7e3726-8f90-4ca9-9269-731987907051")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
24
MyCode.Project.OutSideService/app.config
Normal file
24
MyCode.Project.OutSideService/app.config
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||
</dependentAssembly>
|
||||
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
|
||||
10
MyCode.Project.OutSideService/packages.config
Normal file
10
MyCode.Project.OutSideService/packages.config
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Senparc.CO2NET" version="0.4.4" targetFramework="net461" />
|
||||
<package id="Senparc.CO2NET.APM" version="0.2.2" targetFramework="net461" />
|
||||
<package id="Senparc.NeuChar" version="0.5.5.2" targetFramework="net461" />
|
||||
<package id="Senparc.Weixin" version="6.3.4" targetFramework="net461" />
|
||||
<package id="Senparc.Weixin.MP" version="16.6.0" targetFramework="net461" />
|
||||
<package id="Senparc.Weixin.TenPay" version="1.1.2" targetFramework="net461" />
|
||||
<package id="Senparc.Weixin.WxOpen" version="3.3.0" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user