Next article: discuz! NT forums, website users, and Forum users are unified and synchronized. (1)
When registering a Website member, synchronize the member information to the Forum:
Try {string cookiedomain = ".bubufx.com"; // your domain name discuzsession DS = websamplehelper. discuzsessionhelper. getsession (); discuz. toolkit. user user = NULL; If (user = NULL | user. username! = T_member_loginname) {int uid = Ds. getuserid (t_member_loginname); If (UID <1) {uid = Ds. register (t_member_loginname, formsauthentication. hashpasswordforstoringinconfigfile (t_member_loginpass, "MD5 "). tolower (), t_member_email, true);} else Ds. login (UID, t_member_loginpass, true, 10000, cookiedomain) ;}} catch {}
Change the synchronization password:
Try {discuzsession DS = websamplehelper. discuzsessionhelper. getsession (); discuz. toolkit. User user = NULL; If (user = NULL | user. Username! = Cm. memberloginname) {int uid = Ds. getuserid (cm. memberloginname); If (UID> 0) {Ds. changeuserpassword (UID, loginpassold, loginpass, loginpass, "") ;}} catch {}
When registering a user, you will encounter the following exception: the call_id submitted by the current session is not greater than the previous call_id
This error occurs when the discuztoolkit thread is synchronized. This problem is caused by the sign method of discuz. toolkit. util. Here, it generates a call_id for each API request.
List. Add (discuzparam. Create ("call_id", datetime. Now. ticks ));
Make the following modifications to completely solve this problem:
Replace the following in the util. CS file of the original discuztoolkit project:Code:
Public static xmlserializer getserializer (type T) {int type_hash = T. gethashcode (); If (! Serialize (type_hash) serializer_dict.add (type_hash, new xmlserializer (t); Return serializer_dict [type_hash];} public discuzparam [] Sign (string method_name, discuzparam [] parameters) {list <discuzparam> List = new list <discuzparam> (parameters); list. add (discuzparam. create ("method", method_name); list. add (discuzparam. create ("api_key", api_key); list. add (discuzparam. create ("call _ Id ", datetime. Now. ticks); list. Sort (); stringbuilder values = new stringbuilder (); foreach (discuzparam Param in list) {If (! String. isnullorempty (Param. value) values. append (Param. tostring ();} values. append (secret); byte [] md5_result = md5.create (). computehash (encoding. utf8.getbytes (values. tostring (); stringbuilder sig_builder = new stringbuilder (); foreach (byte B in md5_result) sig_builder.append (B. tostring ("X2"); list. add (discuzparam. create ("sig", sig_builder.tostring (); return list. toarray ();}
changed to:
Public static xmlserializer getserializer (type T) {int type_hash = T. gethashcode (); If (! Serialize (type_hash) serializer_dict.add (type_hash, new xmlserializer (t); Return serializer_dict [type_hash];} public discuzparam [] Sign (string method_name, discuzparam [] parameters) {list <discuzparam> List = new list <discuzparam> (parameters); list. add (discuzparam. create ("method", method_name); list. add (discuzparam. create ("api_key", api_key); // list. add (discuzparam. create ("ca Ll_id ", datetime. now. ticks); // lock (this) {list. add (discuzparam. create ("call_id", datetime. now. ticks); // avoid to generate same 'call _ id' and throws an exception on 'The call_id submitted by the current session is not greater than the previous call_id '. system. threading. thread. sleep (50);} // list. sort (); stringbuilder values = new stringbuilder (); foreach (discuzparam Param in list) {If (! String. isnullorempty (Param. value) values. append (Param. tostring ();} values. append (secret); byte [] md5_result = md5.create (). computehash (encoding. utf8.getbytes (values. tostring (); stringbuilder sig_builder = new stringbuilder (); foreach (byte B in md5_result) sig_builder.append (B. tostring ("X2"); list. add (discuzparam. create ("sig", sig_builder.tostring (); return list. toarray ();}
This problem is completely solved.
Bu shares original technologies. For more information, see:Http://tech.bubufx.com/infodetail_25.html