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 { /// /// 验证企业号签名 /// /// 企业号配置的Token /// 签名内容 /// 时间戳 /// nonce参数 /// 企业号ID标识 /// 加密键 /// 内容字符串 /// 返回的字符串 /// 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; } } }