検索
ホームページWeChat アプレットWeChatの開発.NET を使用して WeChat パブリック プラットフォームを開発するための地理的位置の例の詳細な説明

この記事は主に、WeChat パブリック プラットフォームの開発のための地理的位置 .Net コードの詳細な分析を提供します。興味のある友人は参照してください

WeChat パブリック プラットフォームには地理的位置に関係する 2 つの状況があります:
最初に、私が送信します。自ら選択した地理的位置を WeChat に送信すると、WeChat は応答情報を自動的にフィードバックできます。
二番目に、WeChat に GPS 測位住所の位置を取得させ、応答情報をフィードバックさせます。まず最初に、WeChat ではテキスト、写真、音声などの送信に加えて、地理的位置という情報がもう 1 つあります。属性:
rreeeeは考慮から外れます。私たち自身が送信した地理情報の場所は必ずしも実際の場所ではないため、ここでの地理情報の場所は承認を必要としないことに注意してください。プライバシーに関与することなく、入力インターフェイスで任意の選択を行うことができます。

。次に、ユーザー自身が、WeChat をフォローするときに WeChat 公開アカウントが私の位置情報を取得することを許可します。これには、記事の冒頭で紹介した 2 番目の状況を使用する必要があります。 WeChatの説明によると、セッションが開始されるとき(つまり、会話インターフェイスに入るとき)に最初に取得され、その後は5秒ごとに自動的に取得されます。つまり、ユーザーの位置情報を取得するときにトリガーされるのは、「あなたと私の会話」ではなく、5秒ごとに発生する特別なイベントです。ここではMsgTypeを「イベント」と定義しており、他の「イベント」と区別するため、EventName(実際の正式名称はイベント)は「LOCATION」(大文字)としています。以下では、WeChat の形式に従って wxmessage クラスを変更する必要があります:

class wxmessage 
  { 
    public string FromUserName { get; set; } 
    public string ToUserName { get; set; } 
    public string MsgType { get; set; } 
    public string EventName { get; set; } 
    public string Content { get; set; }
    public string Recognition { get; set; }
    public string MediaId { get; set; }
    public string EventKey { get; set; } 
    public string Location_X { get; set; }
    public string Location_Y { get; set; }
    public string Scale { get; set; }
    public string Label { get; set; }

  }    其中Location_X代表纬度,Location_Y代表经度,Scale代表缩放比例,Label代表位置的描述
    和接受文本,语音消息一下样,地理信息的MsgType为“location”,修改一下之前的GetWxMessage()函数和OnLoad里面的消息处理:
 
private wxmessage GetWxMessage()
   {
     wxmessage wx = new wxmessage();
     StreamReader str = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8);
     XmlDocument xml = new XmlDocument();
     xml.Load(str);
     wx.ToUserName = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText;
     wx.FromUserName = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText;
     wx.MsgType = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText;
     if (wx.MsgType.Trim() == "text")
     {
       wx.Content = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText;
     }
     if (wx.MsgType.Trim() == "location")
     {
       wx.Location_X = xml.SelectSingleNode("xml").SelectSingleNode("Location_X").InnerText;
       wx.Location_Y = xml.SelectSingleNode("xml").SelectSingleNode("Location_Y").InnerText;
       wx.Scale = xml.SelectSingleNode("xml").SelectSingleNode("Scale").InnerText;
       wx.Label = xml.SelectSingleNode("xml").SelectSingleNode("Label").InnerText;

     }
     if (wx.MsgType.Trim() == "event")
     {
       wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
       wx.EventKey = xml.SelectSingleNode("xml").SelectSingleNode("EventKey").InnerText;
     }
     if (wx.MsgType.Trim() == "voice")
     {
       wx.Recognition = xml.SelectSingleNode("xml").SelectSingleNode("Recognition").InnerText;
     }
     
     return wx;
   }
  protected void Page_Load(object sender, EventArgs e)
   {
     wxmessage wx = GetWxMessage();
     string res = "";


     if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "subscribe")
     {
       string content = "";
       if (!wx.EventKey.Contains("qrscene_"))
       {
         content = "/:rose欢迎北京永杰友信科技有限公司/:rose\n直接回复“你好”";
         res = sendTextMessage(wx, content);
       }
       else
       {
         content = "二维码参数:\n" + wx.EventKey.Replace("qrscene_", "");
         res = sendTextMessage(wx, content);
       }
     }

     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.ToLower() == "scan")
     {
       string str = "二维码参数:\n" + wx.EventKey;
       res = sendTextMessage(wx, str);
     }
     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "CLICK")
     {
       if(wx.EventKey=="HELLO")
         res = sendTextMessage(wx, "你好,欢迎使用北京永杰友信科技有限公司公共微信平台!");
     }
     else
     {
       WriteLog(wx.MsgType);
       if (wx.MsgType == "text" && wx.Content == "你好")
       {
         res = sendTextMessage(wx, "你好,欢迎使用北京永杰友信科技有限公司公共微信平台!");
       }
       else if (wx.MsgType == "voice")
       {
         res = sendTextMessage(wx, wx.Recognition);
       }
       else if (wx.MsgType == "location")
       {
         res = sendTextMessage(wx, "您发送的位置是:" + wx.Label + ";纬度是:" + wx.Location_X + ";经度是:" + wx.Location_Y + ";缩放比例为:" + wx.Scale);
       }
       else
       {
         res = sendTextMessage(wx, "你好,未能识别消息!");
       }
     }

     Response.Write(res);
   }

msgtype がイベントの場合、メニュー イベントを使用しました。ここで、eventName のコード セグメントを「local」として追加する必要があります。 now 他のイベントが関与していない場合は、後で else を使用して、より標準化されたコードを書きます。ここでは、3 つの新しい属性を新しい属性に割り当て、ONLOAD 関数
 class wxmessage 
  { 
    public string FromUserName { get; set; } 
    public string ToUserName { get; set; } 
    public string MsgType { get; set; } 
    public string EventName { get; set; } 
    public string Content { get; set; }
    public string Recognition { get; set; }
    public string MediaId { get; set; }
    public string EventKey { get; set; } 
    public string Location_X { get; set; }
    public string Location_Y { get; set; }
    public string Scale { get; set; }
    public string Label { get; set; }
    public string Latitude { get; set; }
    public string Longitude { get; set; }
    public string Precision { get; set; }

  }
    改造一下GetWxMessage()函数和OnLoad函数:
 
private wxmessage GetWxMessage()
   {
     wxmessage wx = new wxmessage();
     StreamReader str = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8);
     XmlDocument xml = new XmlDocument();
     xml.Load(str);
     wx.ToUserName = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText;
     wx.FromUserName = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText;
     wx.MsgType = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText;
     WriteLog("MsgType:"+wx.MsgType);
     if (wx.MsgType.Trim() == "event")
     {
       wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
       WriteLog(wx.EventName);
       if (wx.EventName.ToUpper() == "LOCATION")
       {
         wx.Latitude = xml.SelectSingleNode("xml").SelectSingleNode("Latitude").InnerText;
         wx.Longitude = xml.SelectSingleNode("xml").SelectSingleNode("Longitude").InnerText;
         wx.Precision = xml.SelectSingleNode("xml").SelectSingleNode("Precision").InnerText;
       }
       else
       {
         wx.EventKey = xml.SelectSingleNode("xml").SelectSingleNode("EventKey").InnerText;
       }
     }
     if (wx.MsgType.Trim() == "text")
     {
       wx.Content = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText;
     }
     if (wx.MsgType.Trim() == "location")
     {
       wx.Location_X = xml.SelectSingleNode("xml").SelectSingleNode("Location_X").InnerText;
       wx.Location_Y = xml.SelectSingleNode("xml").SelectSingleNode("Location_Y").InnerText;
       wx.Scale = xml.SelectSingleNode("xml").SelectSingleNode("Scale").InnerText;
       wx.Label = xml.SelectSingleNode("xml").SelectSingleNode("Label").InnerText;

     }
     if (wx.MsgType.Trim() == "voice")
     {
       wx.Recognition = xml.SelectSingleNode("xml").SelectSingleNode("Recognition").InnerText;
     }
     
     return wx;
   }

を変更して完了します。これにより、WeChat の「ユーザー位置情報」を開いたときに、WeChat プラットフォームはセッションに入るのみであることを通知します。初めて取得するか、5 秒ごとに取得するか、後者を選択すると、地理的位置情報が 5 秒ごとにフィードバックされることがわかります。注意する必要があります: これによると問題ないと思いますが、セッションに入ると、GPS 測位の前に携帯電話の GPS が検索されていることがわかります。 , コンテンツは表示されません。 GPS で検索して位置を特定すると、ユーザーの位置情報を取得するイベントがトリガーされることがわかりますが、これは、基地局の測位によっておおよその位置が取得できるということを私が想像していたものではありません。長い間それをしていて、外出したときに携帯電話の位置を確認し、偶然返信を見て、はっと気づきました。

しかし、誰もが緯度と経度の座標のみを知っていることの使用は何ですか?特定の場所ではありません。実際には、BaiduMap API の逆住所解析を使用して、どの都市、どの街路などの座標をガイドし、さらに近くの状況を知るために、さまざまな方法を使用できます。とはいえ、BaiduMapについてはまた機会があればお話しします

以上が.NET を使用して WeChat パブリック プラットフォームを開発するための地理的位置の例の詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!