Home > Net >  Nailing registered callback interface c # 2
Nailing registered callback interface c # 2

Time:11-18

Who have a sample?


Register. HTML - ajax calls to the Register. Ashx registered http://221. * * *. * *. 130:8013/Ding. Ashx interface, to do the processing of certain instances of examination and approval,

Registered return point above errors, how to trace to Ding. Ashx, point to Register set breakpoints, directly Register. Ashx performed ended
Register. Ashx
-- -- -- -- -- -- -- --
Public void the ProcessRequest (HttpContext context)
{


The context. The Response. ContentType="text/plain";

String accToken=DingDll. SqlHelper. ReadToken ();//access Token
DefaultDingTalkClient client=new DefaultDingTalkClient (Urls. RegisterCallBack);
OapiCallBackRegisterCallBackRequest the req=new OapiCallBackRegisterCallBackRequest ();
The req. Url="http://221. * * * *. 130:8013/Ding ashx";
The req. AesKey="45 skhqweass5232345iujkwedl5251054dsfdsuhfw2";//randomly generated 43 string
The req. Token="123456";//random fill out
List ArrMsg=new List (a);//fill in the information to monitor
Bpms_task_change arrMsg. Add (" ");
Bpms_instance_change arrMsg. Add (" ");
The req. CallBackTag=arrMsg;
OapiCallBackRegisterCallBackResponse rep=client. The Execute (the req, accToken);
String ss=rep. Body;
The context. The Response. The Write (ss);
}

Ding. Ashx
-- -- -- -- -- -- -- --
Public class Ding: IHttpHandler {

///
///Request Form (" EventType ")
///

Public string EventType {get; The set; }

Private string GetPostParam (HttpContext context)
{
If (" POST "==context. Request. RequestType)
{
Stream sm=context. Request. InputStream;//get the post body
Int len=(int) sm. Length;//post data length
Byte [] inputByts=new byte (len);//byte data, used to store the post data
Sm. Read (inputByts, 0, len);//will post data to byte array
Sm. The Close ();//close the IO flow

//* * * * * * * * * * the following is the type of an array of bytes into a string of * * * * * * * * * *

String data=https://bbs.csdn.net/topics/Encoding.UTF8.GetString (inputByts);//to String
Encrypt data=https://bbs.csdn.net/topics/data.Replace (" {\ "", \ ""," "). The Replace (" \ "} ", "");
return data;
}
Return "the get method";
}


Public void the ProcessRequest (HttpContext context) {

Try
{
# region for suite configuration parameter
String mToken=ConfigurationManager. AppSettings (" Token ");
//string mSuiteKey="";
String mEncodingAesKey=ConfigurationManager. AppSettings [" EncodingAESKey "];

String mSuiteKey=ConfigurationManager. AppSettings [" corpid "];

//mSuiteKey="suite4xxxxxxxxxxxxxxx";
# endregion

# region for the inside of the callback URL parameter
//in the url signature
String msgSignature=context. The Request (" signature ");
//in the url timestamp
String timeStamp=context. Request (" timeStamp ");
//url in a random string
String nonce=context. Request [" nonce "];
//post data packet in the data encryption
String encryptStr=GetPostParam (context);
# endregion

String sEchoStr="";

//# region validation callback url
////SuiteAuth SuiteAuth=new SuiteAuth ();
DingDll. DingTalkCrypt ding=new DingTalkCrypt (mToken mEncodingAesKey, mSuiteKey);

Var ret=ding. VerifyURL (msgSignature, timeStamp, nonce, encryptStr, ref sEchoStr);

If (ret!=0)
{
The context. The Response. The Write (" ERR: VerifyURL fail, ret: "+ ret);
return;
}
//# endregion

# region
//structure 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 [r]. "eventType" ToString ();
String res="success";
The switch (eventType)

Case "bpms_task_change" ://approval task, transfer over,
break;
Case "bpms_instance_change" :
break;
}

TimeStamp=DingTalking. GetTimeStamp (System. A DateTime. Now). The 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}
};
The string result=JsonConvert. SerializeObject (jsonMap);
The context. The Response. The Write (result);
# endregion
}
The catch (Exception ex)
{
Throw new Exception (DateTime. Now + ex. Message);
}
}





Public bool IsReusable {
The get {
return false;
}
}

}

CodePudding user response:

https://developer.aliyun.com/ask/250318? SPM=a2c6h. 13524658
Application and development, if not on the same computer machine use remote debugging to do debug
https://blog.csdn.net/zhouschina/article/details/77513235
Actually error has clearly said that the previous parameter errors, such as is not in accordance with the document to get
https://ding-doc.dingtalk.com/doc#/faquestions/ltr370
He has the SDK with demo here
  •  Tags:  
  • C#
  • Related