using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Xml;
|
using Tencent;
|
|
namespace BatchService.Framework.Utility
|
{
|
public class CorpBasicApi
|
{
|
/// <summary>
|
/// 验证企业号签名
|
/// </summary>
|
/// <param name="token">企业号配置的Token</param>
|
/// <param name="signature">签名内容</param>
|
/// <param name="timestamp">时间戳</param>
|
/// <param name="nonce">nonce参数</param>
|
/// <param name="corpId">企业号ID标识</param>
|
/// <param name="encodingAESKey">加密键</param>
|
/// <param name="echostr">内容字符串</param>
|
/// <param name="retEchostr">返回的字符串</param>
|
/// <returns></returns>
|
public bool CheckSignature(string token, string signature, string timestamp, string nonce, string corpId, string encodingAESKey, string echostr, ref string retEchostr)
|
{
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAESKey, corpId);
|
int result = wxcpt.VerifyURL(signature, timestamp, nonce, echostr, ref retEchostr);
|
if (result != 0)
|
{
|
LogHelper.Error("ERR: VerifyURL fail, ret: " + result);
|
return false;
|
}
|
|
return true;
|
|
//ret==0表示验证成功,retEchostr参数表示明文,用户需要将retEchostr作为get请求的返回参数,返回给企业号。
|
// HttpUtils.SetResponse(retEchostr);
|
}
|
|
public bool DecodeMessage(string i_token, string i_encodingAESKey, string i_corpId,string i_msg_signature, string i_sReqTimeStamp, string i_sReqNonce, string i_sReqData,ref string o_ret)
|
{
|
bool t_is_deocde = false;
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(i_token, i_encodingAESKey, i_corpId);
|
int t_ret = wxcpt.DecryptMsg(i_msg_signature, i_sReqTimeStamp, i_sReqNonce, i_sReqData, ref o_ret);
|
|
if (t_ret != 0)
|
{
|
LogHelper.Error("ERR: DecryptMsg fail, ret: " + t_ret);
|
return false;
|
}
|
//LogHelper.Info(o_ret);
|
|
return true;
|
}
|
|
public bool EncodeMessage(string i_token, string i_encodingAESKey, string i_corpId, string i_sReqTimeStamp, string i_sReqNonce, string i_sReqData, ref string o_ret)
|
{
|
bool t_is_deocde = false;
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(i_token, i_encodingAESKey, i_corpId);
|
int t_ret = wxcpt.EncryptMsg(i_sReqData, i_sReqTimeStamp, i_sReqNonce, ref o_ret);
|
|
if (t_ret != 0)
|
{
|
LogHelper.Error("ERR: DecryptMsg fail, ret: " + t_ret);
|
return false;
|
}
|
|
return t_is_deocde;
|
}
|
}
|
}
|