.net寰俊鍏紬鍙峰紑鍙戔€斺€旀秷鎭笌浜嬩欢
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.net寰俊鍏紬鍙峰紑鍙戔€斺€旀秷鎭笌浜嬩欢相关的知识,希望对你有一定的参考价值。
鏍囩锛?/p>
鏈枃浠嬬粛濡備綍澶勭悊寰俊鍏紬鍙峰紑鍙戜腑鐨勬秷鎭笌浜嬩欢锛屽寘鎷細锛?锛夋秷鎭紙浜嬩欢锛夋鍐碉紱锛?锛夐獙璇佹秷鎭殑鐪熷疄鎬э紱锛?锛夎В鏋愭秷鎭紱锛?锛夎鍔ㄥ洖澶嶆秷鎭紱锛?锛夊彂閫佸叾浠栨秷鎭€?br /> 寮€婧愰」鐩湴鍧€锛?a href="https://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount" target="_blank">http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount
鏈枃婧愪唬鐮佹瘮杈冨垎鏁o紝涓昏鍦細
http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount/blob/master/xrwang.net/WeixinInterface.ashx
http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount/blob/master/xrwang.net/Example/ParseRequestMessage.aspx.cs
http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount/tree/master/PublicAccount/RequestMessage
http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount/tree/master/PublicAccount/ResponseMessage
鏈枃鐨勬紨绀哄湴鍧€锛?br /> 锛?锛?a href="http://xrwang.net/Example/ParseRequestMessage.aspx" target="_blank">http://xrwang.net/Example/ParseRequestMessage.aspx
锛?锛夊叧娉ㄦ垜鐨勫叕浼楀彿锛屽苟鍙戦€佹秷鎭?/p>
娴嬭瘯鍙?/p> |
|
娴嬭瘯鍙锋潈闄愬锛屽嚑涔庡彲浠ユ祴璇曞叕浼楀钩鍙扮殑鎵€鏈夊姛鑳姐€?/p> |
鎴戠殑鍏紬鍙?/p> xrwang |
|
涓汉璁㈤槄鍙凤紝鍔熻兘杈冨皯锛屼笉杩囨垜浼氱壒鍒紭鍖栥€?/p> |
1 娑堟伅锛堜簨浠讹級姒傚喌
褰撴櫘閫氬井淇$敤鎴峰悜鍏紬鍙峰彂娑堟伅鎴栬€呭井淇℃湇鍔″櫒鍚戝叕浼楀彿鎺ㄩ€佷簨浠舵椂锛屽井淇℃湇鍔″櫒灏哖OST娑堟伅锛堜簨浠讹級鐨刋ML鏁版嵁鍖呭埌寮€鍙戣€呭~鍐欑殑鍏紬鍙锋湇鍔″櫒URL涓婏紱鍏紬鍙锋湇鍔″櫒鐒跺悗瀵规秷鎭綔鍑哄搷搴斻€?br />1.1 娑堟伅鐨勬祦杞繃绋?/strong>
涓轰簡渚夸簬鍖哄垎锛屾垜浠皢寰俊鏈嶅姟鍣ㄥ彂寰€鍏紬鍙锋湇鍔″櫒鐨勬秷鎭О涓鸿姹?Request)娑堟伅锛涘皢鍏紬鍙锋湇鍔″櫒鍙戝線寰俊鏈嶅姟鍣ㄧ殑娑堟伅绉颁负鍝嶅簲(Response)娑堟伅锛涘皢鎺ㄩ€佷簨浠剁湅鎴愮壒娈婄殑璇锋眰娑堟伅銆?br /> 璇锋眰涓庡搷搴旀秷鎭殑娴佽浆杩囩▼濡備笅鍥炬墍绀猴細
1.2 璇锋眰娑堟伅
璇锋眰娑堟伅鏈夊緢澶氱锛屾垜浠负鍏朵竴涓€寤虹珛浜嗗搴旂殑绫伙紝绫诲眰娆$粨鏋勫涓嬪浘鎵€绀猴細
鏈変簺璇锋眰娑堟伅锛屾垜浠彲浠ュ仛鍑哄搷搴旓紝鏈変簺鍒欎笉鑳斤紝璇﹁涓嬭〃锛?/p>
娑堟伅绫诲瀷 | 鏄惁浜嬩欢 | 鑳藉琚姩鍥炲 | 澶囨敞 |
鏂囨湰 | × | √ | |
鍥剧墖 | × | √ | |
澹伴煶 | × | √ | |
瑙嗛 | × | 鏈煡 | 鎺ユ敹涓嶅埌瑙嗛娑堟伅锛屼笉鐭ラ亾鏄惁鑳借鍔ㄥ洖澶?/td> |
鍦扮悊浣嶇疆 | × | √ | |
閾炬帴 | × | √ | |
璁㈤槄 | √ | √ | |
鍙栨秷璁㈤槄 | √ | × | |
鎵弿浜岀淮鐮?/td> | √ | × | |
涓婃姤鍦扮悊浣嶇疆 | √ | × | |
鐐瑰嚮鑿滃崟鎷夊彇娑堟伅 | √ | √ | |
鐐瑰嚮鑿滃崟璺宠浆閾炬帴 | √ | × | |
鐐瑰嚮鑿滃崟鎵爜鎺?/td> | √ | × | |
鐐瑰嚮鑿滃崟鎵爜绛夊緟鍥炲 | √ | √ | |
鐐瑰嚮鑿滃崟绯荤粺鍙戝浘 | √ | 鏈煡 | 鎺ユ敹涓嶅埌绯荤粺鍙戝浘浜嬩欢锛涘井淇℃湇鍔″櫒浼氬彂閫佸浘鐗囨秷鎭紝鍙洖澶?/td> |
鐐瑰嚮鑿滃崟鎷嶇収鎴栫浉鍐屽彂鍥?/td> | √ | × | 寰俊鏈嶅姟鍣ㄤ細鍙戦€佸浘鐗囨秷鎭紝鍙洖澶?/td> |
鐐瑰嚮鑿滃崟寰俊鍙戝浘 | √ | × | 寰俊鏈嶅姟鍣ㄤ細鍙戦€佸浘鐗囨秷鎭紝鍙洖澶?/td> |
鐐瑰嚮鑿滃崟閫夋嫨鍦扮悊浣嶇疆 | √ | × | 寰俊鏈嶅姟鍣ㄤ細鍙戦€佸湴鐞嗕綅缃秷鎭紝鍙洖澶?/td> |
鎺ㄩ€佺兢鍙戞秷鎭粨鏋?/td> | √ | × | |
鎺ㄩ€佸彂閫佹ā鏉挎秷鎭粨鏋?/td> | √ | × |
1.3 鍝嶅簲娑堟伅
鍝嶅簲娑堟伅鐨勭被灞傛缁撴瀯濡備笅鍥炬墍绀猴細
3 瑙f瀽娑堟伅 濡傛灉娑堟伅绛惧悕閫氳繃楠岃瘉锛屾垜浠渶瑕佸皢XML鏍煎紡鐨勬秷鎭枃鏈В鏋愭垚璇锋眰娑堟伅瀵硅薄锛孯equestMessageHelper绫荤敤浜庡畬鎴愯繖椤瑰伐浣溿€?/p>
娑堟伅瑙f瀽鎴愬姛涔嬪悗锛宧elper.Message涓烘秷鎭熀绫籖equestBaseMessage锛屾垜浠彲浠ユ牴鎹睘鎬sgType鍙奅vent鍒ゆ柇鍒板簳鏄摢绉嶆秷鎭紙浜嬩欢锛夛紝骞惰浆鎹㈡垚閫傚綋鐨勫瓙绫诲瀷銆備緥濡傦細 瑙f瀽娑堟伅鐨勭粏鑺傝鍙傜湅婧愪唬鐮侊細http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount/blob/master/PublicAccount/RequestMessage/RequestMessageHelper.cs 4 琚姩鍥炲娑堟伅 5 鍙戦€佸叾浠栨秷鎭?/strong>
2 楠岃瘉娑堟伅鐨勭湡瀹炴€?/strong>
鍏紬鍙锋湇鍔″櫒鎺ユ敹鍒板井淇℃湇鍔″櫒鐨勮姹備箣鍚庯紝绗竴浠朵簨鎯呮槸楠岃瘉娑堟伅鐨勭湡瀹炴€с€?br /> Utility.CheckSignature鏂规硶鐢ㄤ簬楠岃瘉娑堟伅绛惧悕鏄惁姝g‘銆?br /> 绀轰緥濡備笅锛?/p>
/// <summary>
/// 楠岃瘉娑堟伅鐨勬湁鏁堟€?
/// </summary>
/// <param name="context"></param>
/// <returns>濡傛灉娑堟伅鏈夋晥锛岃繑鍥瀟rue锛涘惁鍒欒繑鍥瀎alse銆?span style="color: #808080;"></returns>
private bool Validate(HttpContext context)
{
string username = RequestEx.TryGetQueryString("username"); //鍦ㄦ帴鍙i厤缃殑URL涓姞鍏ヤ簡username鍙傛暟锛岃〃绀哄摢涓井淇″叕浼楀彿
AccountInfo account = AccountInfoCollection.GetAccountInfo(username);
if (account == null)
return false;
string token = account.Token;
string signature = RequestEx.TryGetQueryString("signature");
string timestamp = RequestEx.TryGetQueryString("timestamp");
string nonce = RequestEx.TryGetQueryString("nonce");
if (string.IsNullOrWhiteSpace(signature) || string.IsNullOrWhiteSpace(timestamp) || string.IsNullOrWhiteSpace(nonce))
return false;
return xrwang.weixin.PublicAccount.Utility.CheckSignature(signature, token, timestamp, nonce);
}
RequestMessageHelper helper = new RequestMessageHelper(context.Request);
if(helper.Message != null)
{
//娑堟伅瑙f瀽鎴愬姛锛屽瀹冭繘琛屽鐞?
}
RequestBaseMessage bm=helper.Message;
switch(bm.MsgType)
{
case RequestMessageTypeEnum.text: //鏂囨湰娑堟伅
HandleTextMessage((RequestTextMessage)bm);
break;
case RequestMessageTypeEnum.image: //鍥剧墖娑堟伅
HandleImageMessage((RequestImageMessage)bm);
break;
//澶勭悊鍏朵粬娑堟伅
case RequestMessageTypeEnum.event: //浜嬩欢
RequestEventMessage ev=(RequestEventMessage)bm;
switch(ev.Event)
{
case RequestEventTypeEnum.subscribe: //璁㈤槄
HandleSubscribeMessage((RequestSubscribeMessage)ev);
break;
case RequestEventTypeEnum.unsubscribe: //鍙栨秷璁㈤槄
HandleUnsubscribeMessage((RequestUnsubscribeMessage)ev);
break;
//澶勭悊鍏朵粬浜嬩欢
}
break;
default:
break;
}
浠庡井淇℃湇鍔″櫒鎺ユ敹鍒版秷鎭紙浜嬩欢锛変箣鍚庯紝鎴戜滑鍙互鍦?绉掍箣鍐呯洿鎺ワ紙琚姩锛夊洖澶嶆秷鎭紱涔熷彲浠ュ厛鐩存帴鍥炲绌哄瓧绗︿覆锛岀劧鍚庡啀鍦?8灏忔椂鍐呭洖澶嶅鏈嶆秷鎭€?br /> 鍏堝垵濮嬪寲ResponseXxxMessage锛岀劧鍚庣敤ToXml鏂规硶寰楀埌鍝嶅簲娑堟伅鍐呭銆?br /> 琚姩鍥炲娑堟伅鐨勭ず渚嬪涓嬶細 /// <summary>
/// 澶勭悊寰俊鐨凱OST璇锋眰
/// </summary>
/// <param name="context"></param>
/// <returns>杩斿洖xml鍝嶅簲</returns>
private string HandlePost(HttpContext context)
{
RequestMessageHelper helper = new RequestMessageHelper(context.Request);
if (helper.Message != null)
{
ResponseBaseMessage responseMessage = HandleRequestMessage(helper.Message);
return responseMessage.ToXml(helper.EncryptType);
}
else
return string.Empty;
}
/// <summary>
/// 澶勭悊璇锋眰娑堟伅锛岃繑鍥炲搷搴旀秷鎭?
/// </summary>
/// <returns>杩斿洖鍝嶅簲娑堟伅</returns>
private ResponseBaseMessage HandleRequestMessage(RequestBaseMessage requestMessage)
{
ResponseTextMessage response = new ResponseTextMessage(requestMessage.FromUserName, requestMessage.ToUserName,
DateTime.Now, string.Format("鑷姩鍥炲锛岃姹傚唴瀹瑰涓嬶細\r\n{0}", requestMessage));
return response;
}
闄や簡琚姩鍥炲娑堟伅涔嬪锛屾垜浠繕鍙互鍙戦€佸鏈嶆秷鎭€佺兢鍙戞秷鎭€佸彂閫佹ā鏉挎秷鎭紝杩欎簺鍐呭灏嗗湪鍚庣画鏂囩珷涓竴涓€閬撴潵銆?/p>
以上是关于.net寰俊鍏紬鍙峰紑鍙戔€斺€旀秷鎭笌浜嬩欢的主要内容,如果未能解决你的问题,请参考以下文章
QGIS 3.14鎻掍欢寮€鍙戔€斺€擶in10绯荤粺PyCharm寮€鍙戠幆澧冩惌寤哄洓姝ヨ蛋
java 鎵弿寰俊鍏紬鍙蜂簩缁寸爜锛屽叧娉ㄥ苟鐧诲綍閫昏緫
灏忕▼搴忕煭瑙嗛椤圭洰鈥斺€斺€斿紑鍙戠敤鎴蜂俊鎭箣鐢ㄦ埛閫€鍑烘敞閿€
鎰熻阿寰蒋澶т腑鍗庡尯寮€鍙戝伐鍏峰強骞冲彴浜嬩笟閮ㄦ€荤粡鐞嗚阿鎭╀紵鍏堢敓瀵瑰叞宸炵數绔為绾㈡槦瓒崇悆鏉疭2鐨勬敮鎸侊紝绗竴鍚嶅彲棰濆鑾疯禒璋㈡仼浼熷厛鐢熶翰绗旂鍚嶆捣鎶ワ紒