ISV 创建套件,回调URL 解析eventType 老是返回 checkcreatesuiteurl
ReISV 创建套件,回调URL 解析eventType 老是返回 checkcreatesuiteurl
#region 获取套件配置参数
string mToken = ConfigurationManager.AppSettings['Token'];
string mSuiteKey = '';
string mEncodingAesKey = ConfigurationManager.AppSettings['EncodingAESKey'];
mSuiteKey = 'suite4xxxxxxxxxxxxxxx';
#endregion
#region 获取回调URL里面的参数
//url中的签名
string msgSignature = context.Request['signature'];
//url中的时间戳
string timeStamp = context.Request['timestamp'];
//url中的随机字符串
string nonce = context.Request['nonce'];
//post数据包数据中的加密数据
string encryptStr = GetPostParam(context);
#endregion
Helper.WriteLog('post方法');
string sEchoStr = '';
#region 验证回调的url
SuiteAuth suiteAuth = new SuiteAuth();
Helper.WriteLog('mToken: ' + mToken);
Helper.WriteLog('mEncodingAesKey: ' + mEncodingAesKey);
Helper.WriteLog('msgSignature: ' + msgSignature);
Helper.WriteLog('timeStamp: ' + timeStamp);
Helper.WriteLog('nonce: ' + nonce);
Helper.WriteLog('encryptStr: ' + encryptStr);
var ret = suiteAuth.VerifyURL(mToken, mEncodingAesKey, msgSignature, timeStamp, nonce, encryptStr,
ref mSuiteKey);
if (ret != 0)
{
Helper.WriteLog('ERR: VerifyURL fail, ret: ' + ret);
return;
}
#endregion
#region
//构造DingTalkCrypt
DingTalkCrypt dingTalk = new DingTalkCrypt(mToken, mEncodingAesKey, mSuiteKey);
string plainText = '';
dingTalk.DecryptMsg(msgSignature, timeStamp, nonce, encryptStr, ref plainText);
Hashtable tb = (Hashtable)JsonConvert.DeserializeObject(plainText, typeof(Hashtable));
string eventType = tb['EventType'].ToString();
string res = 'success';
Helper.WriteLog('plainText:' + plainText);
Helper.WriteLog('eventType:' + eventType);
switch (eventType)-----------------------------------------------------------------------就是在这里,老是获取的是 check_create_suite_url
{
case 'suite_ticket'://定时推送Ticket
ConfigurationManager.AppSettings['SuiteTicket'] = tb['SuiteTicket'].ToString();
mSuiteKey = tb['SuiteKey'].ToString();
suiteAuth.SaveSuiteTicket(tb);
break;
case 'tmp_auth_code'://钉钉推送过来的临时授权码
ConfigurationManager.AppSettings['TmpAuthCode'] = tb['AuthCode'].ToString();
suiteAuth.SaveTmpAuthCode(tb);
break;
case 'change_auth':// do something;
break;
case 'check_update_suite_url':
res = tb['Random'].ToString();
mSuiteKey = tb['TestSuiteKey'].ToString();
break;
}
timeStamp = Helper.GetTimeStamp().ToString();
string encrypt = '';
string signature = '';
dingTalk = new DingTalkCrypt(mToken, mEncodingAesKey, mSuiteKey);
dingTalk.EncryptMsg(res, timeStamp, nonce, ref encrypt, ref signature);
Hashtable jsonMap = new Hashtable
{
{'msg_signature', signature},
{'encrypt', encrypt},
{'timeStamp', timeStamp},
{'nonce', nonce}
};
string result = JsonConvert.SerializeObject(jsonMap);
Helper.WriteLog('result: ' + result);
context.Response.Write(result);
赞0
踩0