.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>

 鎶€鏈垎浜? src=

娴嬭瘯鍙锋潈闄愬锛屽嚑涔庡彲浠ユ祴璇曞叕浼楀钩鍙扮殑鎵€鏈夊姛鑳姐€?/p>

鎴戠殑鍏紬鍙?/p>

xrwang

 鎶€鏈垎浜? src=

涓汉璁㈤槄鍙凤紝鍔熻兘杈冨皯锛屼笉杩囨垜浼氱壒鍒紭鍖栥€?/p>

1 娑堟伅锛堜簨浠讹級姒傚喌
    褰撴櫘閫氬井淇$敤鎴峰悜鍏紬鍙峰彂娑堟伅鎴栬€呭井淇℃湇鍔″櫒鍚戝叕浼楀彿鎺ㄩ€佷簨浠舵椂锛屽井淇℃湇鍔″櫒灏哖OST娑堟伅锛堜簨浠讹級鐨刋ML鏁版嵁鍖呭埌寮€鍙戣€呭~鍐欑殑鍏紬鍙锋湇鍔″櫒URL涓婏紱鍏紬鍙锋湇鍔″櫒鐒跺悗瀵规秷鎭綔鍑哄搷搴斻€?br />1.1 娑堟伅鐨勬祦杞繃绋?/strong>
    涓轰簡渚夸簬鍖哄垎锛屾垜浠皢寰俊鏈嶅姟鍣ㄥ彂寰€鍏紬鍙锋湇鍔″櫒鐨勬秷鎭О涓鸿姹?Request)娑堟伅锛涘皢鍏紬鍙锋湇鍔″櫒鍙戝線寰俊鏈嶅姟鍣ㄧ殑娑堟伅绉颁负鍝嶅簲(Response)娑堟伅锛涘皢鎺ㄩ€佷簨浠剁湅鎴愮壒娈婄殑璇锋眰娑堟伅銆?br />    璇锋眰涓庡搷搴旀秷鎭殑娴佽浆杩囩▼濡備笅鍥炬墍绀猴細

鎶€鏈垎浜? src=

1.2 璇锋眰娑堟伅
    璇锋眰娑堟伅鏈夊緢澶氱锛屾垜浠负鍏朵竴涓€寤虹珛浜嗗搴旂殑绫伙紝绫诲眰娆$粨鏋勫涓嬪浘鎵€绀猴細

鎶€鏈垎浜? src=

鏈変簺璇锋眰娑堟伅锛屾垜浠彲浠ュ仛鍑哄搷搴旓紝鏈変簺鍒欎笉鑳斤紝璇﹁涓嬭〃锛?/p>

娑堟伅绫诲瀷 鏄惁浜嬩欢 鑳藉琚姩鍥炲 澶囨敞
鏂囨湰 ×  
鍥剧墖 ×  
澹伴煶 ×  
瑙嗛 × 鏈煡 鎺ユ敹涓嶅埌瑙嗛娑堟伅锛屼笉鐭ラ亾鏄惁鑳借鍔ㄥ洖澶?/td>
鍦扮悊浣嶇疆 ×  
閾炬帴 ×  
璁㈤槄  
鍙栨秷璁㈤槄 ×  
鎵弿浜岀淮鐮?/td> ×  
涓婃姤鍦扮悊浣嶇疆 ×  
鐐瑰嚮鑿滃崟鎷夊彇娑堟伅  
鐐瑰嚮鑿滃崟璺宠浆閾炬帴 ×  
鐐瑰嚮鑿滃崟鎵爜鎺?/td> ×  
鐐瑰嚮鑿滃崟鎵爜绛夊緟鍥炲  
鐐瑰嚮鑿滃崟绯荤粺鍙戝浘 鏈煡 鎺ユ敹涓嶅埌绯荤粺鍙戝浘浜嬩欢锛涘井淇℃湇鍔″櫒浼氬彂閫佸浘鐗囨秷鎭紝鍙洖澶?/td>
鐐瑰嚮鑿滃崟鎷嶇収鎴栫浉鍐屽彂鍥?/td> × 寰俊鏈嶅姟鍣ㄤ細鍙戦€佸浘鐗囨秷鎭紝鍙洖澶?/td>
鐐瑰嚮鑿滃崟寰俊鍙戝浘 × 寰俊鏈嶅姟鍣ㄤ細鍙戦€佸浘鐗囨秷鎭紝鍙洖澶?/td>
鐐瑰嚮鑿滃崟閫夋嫨鍦扮悊浣嶇疆 × 寰俊鏈嶅姟鍣ㄤ細鍙戦€佸湴鐞嗕綅缃秷鎭紝鍙洖澶?/td>
鎺ㄩ€佺兢鍙戞秷鎭粨鏋?/td> ×  
鎺ㄩ€佸彂閫佹ā鏉挎秷鎭粨鏋?/td> ×  

 

1.3 鍝嶅簲娑堟伅
    鍝嶅簲娑堟伅鐨勭被灞傛缁撴瀯濡備笅鍥炬墍绀猴細

鎶€鏈垎浜? src=


2 楠岃瘉娑堟伅鐨勭湡瀹炴€?/strong>
    鍏紬鍙锋湇鍔″櫒鎺ユ敹鍒板井淇℃湇鍔″櫒鐨勮姹備箣鍚庯紝绗竴浠朵簨鎯呮槸楠岃瘉娑堟伅鐨勭湡瀹炴€с€?br />    Utility.CheckSignature鏂规硶鐢ㄤ簬楠岃瘉娑堟伅绛惧悕鏄惁姝g‘銆?br />    绀轰緥濡備笅锛?/p>

鎶€鏈垎浜? id=
    /// <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);
    }
楠岃瘉娑堟伅鐪熷疄鎬?/span>

 

3 瑙f瀽娑堟伅

    濡傛灉娑堟伅绛惧悕閫氳繃楠岃瘉锛屾垜浠渶瑕佸皢XML鏍煎紡鐨勬秷鎭枃鏈В鏋愭垚璇锋眰娑堟伅瀵硅薄锛孯equestMessageHelper绫荤敤浜庡畬鎴愯繖椤瑰伐浣溿€?/p>

RequestMessageHelper helper = new RequestMessageHelper(context.Request);
if(helper.Message != null)
{
    //娑堟伅瑙f瀽鎴愬姛锛屽瀹冭繘琛屽鐞?
}

    娑堟伅瑙f瀽鎴愬姛涔嬪悗锛宧elper.Message涓烘秷鎭熀绫籖equestBaseMessage锛屾垜浠彲浠ユ牴鎹睘鎬sgType鍙奅vent鍒ゆ柇鍒板簳鏄摢绉嶆秷鎭紙浜嬩欢锛夛紝骞惰浆鎹㈡垚閫傚綋鐨勫瓙绫诲瀷銆備緥濡傦細

鎶€鏈垎浜? id=
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;
}
澶勭悊娑堟伅

瑙f瀽娑堟伅鐨勭粏鑺傝鍙傜湅婧愪唬鐮侊細http://git.oschina.net/xrwang2/xrwang.weixin.PublicAccount/blob/master/PublicAccount/RequestMessage/RequestMessageHelper.cs

4 琚姩鍥炲娑堟伅
    浠庡井淇℃湇鍔″櫒鎺ユ敹鍒版秷鎭紙浜嬩欢锛変箣鍚庯紝鎴戜滑鍙互鍦?绉掍箣鍐呯洿鎺ワ紙琚姩锛夊洖澶嶆秷鎭紱涔熷彲浠ュ厛鐩存帴鍥炲绌哄瓧绗︿覆锛岀劧鍚庡啀鍦?8灏忔椂鍐呭洖澶嶅鏈嶆秷鎭€?br />    鍏堝垵濮嬪寲ResponseXxxMessage锛岀劧鍚庣敤ToXml鏂规硶寰楀埌鍝嶅簲娑堟伅鍐呭銆?br />    琚姩鍥炲娑堟伅鐨勭ず渚嬪涓嬶細

鎶€鏈垎浜? id=
    /// <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;
    }
琚姩鍥炲娑堟伅

 

5 鍙戦€佸叾浠栨秷鎭?/strong>
    闄や簡琚姩鍥炲娑堟伅涔嬪锛屾垜浠繕鍙互鍙戦€佸鏈嶆秷鎭€佺兢鍙戞秷鎭€佸彂閫佹ā鏉挎秷鎭紝杩欎簺鍐呭灏嗗湪鍚庣画鏂囩珷涓竴涓€閬撴潵銆?/p>

以上是关于.net寰俊鍏紬鍙峰紑鍙戔€斺€旀秷鎭笌浜嬩欢的主要内容,如果未能解决你的问题,请参考以下文章

QGIS 3.14鎻掍欢寮€鍙戔€斺€擶in10绯荤粺PyCharm寮€鍙戠幆澧冩惌寤哄洓姝ヨ蛋

java 鎵弿寰俊鍏紬鍙蜂簩缁寸爜锛屽叧娉ㄥ苟鐧诲綍閫昏緫

鍝嶅簲寮忚璁♀€斺€斾互鍙婂紑鍙戝湪璁捐涓殑浣滅敤

灏忕▼搴忕煭瑙嗛椤圭洰鈥斺€斺€斿紑鍙戠敤鎴蜂俊鎭箣鐢ㄦ埛閫€鍑烘敞閿€

寰俊鎺ュ彛鏂囨。sdk

鎰熻阿寰蒋澶т腑鍗庡尯寮€鍙戝伐鍏峰強骞冲彴浜嬩笟閮ㄦ€荤粡鐞嗚阿鎭╀紵鍏堢敓瀵瑰叞宸炵數绔為绾㈡槦瓒崇悆鏉疭2鐨勬敮鎸侊紝绗竴鍚嶅彲棰濆鑾疯禒璋㈡仼浼熷厛鐢熶翰绗旂鍚嶆捣鎶ワ紒

(c)2006-2024 SYSTEM All Rights Reserved IT常识