服务器get不到微信的信息,Get验证通过,Post方法接收不到Signature等参数信息

[HttpPost]

[ActionName("Index")]

public ActionResult Post(PostModel postModel)

{

if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token))

{

using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt")))

{

tw.WriteLine("Sig:" + postModel.Signature);

tw.WriteLine("Tim:" + postModel.Timestamp);

tw.WriteLine("Non:" + postModel.Nonce);

tw.Flush();

tw.Close();

}

return Content("参数错误!");

}

}

PostModel 接收到的参数全部为空,导致签名失败。

[HttpPost]

[ActionName("Index")]

public ActionResult Post(PostModel postModel)

{

if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token))

{

using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt")))

{

tw.WriteLine("Sig:" + postModel.Signature);

tw.WriteLine("Tim:" + postModel.Timestamp);

tw.WriteLine("Non:" + postModel.Nonce);

tw.Flush();

tw.Close();

}

return Content("参数错误!");

}

}

PostModel 接收到的参数全部为空,导致签名失败。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 好的,下面是一个使用 Delphi 在企业微信自建应用中接收用户发送的信息的代码示例。 首先,你需要在企业微信中创建自建应用,并获取到应用的 AgentID 和 Secret。 然后,你需要使用 Delphi 中的网络组件(如 Indy 或 WinHTTP)来发送 HTTP 请求,获取访问令牌(Access Token)。 接下来,你就可以使用访问令牌来用企业微信的消息接收接口接收用户发送的信息。 以下是使用 Indy 发送 HTTP 请求获取访问令牌的代码示例: ``` uses IdHTTP, IdSSLOpenSSL, IdGlobal; var HTTP: TIdHTTP; SSL: TIdSSLIOHandlerSocketOpenSSL; AgentID, Secret, AccessToken: string; TokenResponse: TStringStream; begin AgentID := '你的 AgentID'; Secret := '你的 Secret'; HTTP := TIdHTTP.Create(nil); try SSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); HTTP.IOHandler := SSL; TokenResponse := TStringStream.Create(''); try HTTP.Get('https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + AgentID + '&corpsecret=' + Secret, TokenResponse); AccessToken := TokenResponse.DataString; finally TokenResponse.Free; end; finally HTTP.Free; end; end; ``` 接下来,你可以使用访问令牌用企业微信的消息接收接口接收用户发送的信息。 以下是使用 Indy 发送 HTTP POST 请求接收用户发送的信息的代码示例: ``` uses IdHTTP, IdSSLOpenSSL, IdGlobal; var ### 回答2: Delphi是一种用于创建Windows应用程序的集成开发环境(IDE)。通过企业微信自建应用接收用户的信息,可以使用企业微信提供的开放接口和Delphi的相关组件来实现。 首先,需要在企业微信后台中创建自建应用,并获取到相应的应用ID和应用密钥。 在Delphi中,可以使用`TIdHTTP`组件来发送HTTP请求,使用`TJSONObject`和`TJSONArray`组件来处理JSON数据。下面是一个使用Delphi接收企业微信用户信息的代码示例: ```delphi uses IdHTTP, System.JSON; procedure TForm1.Button1Click(Sender: TObject); var HTTPClient: TIdHTTP; Response: string; JSONData, JSONMessageArray: TJSONArray; i: Integer; MessageContent: string; begin HTTPClient := TIdHTTP.Create(nil); try HTTPClient.Request.BasicAuthentication := False; HTTPClient.Request.CustomHeaders.Add('Content-Type:application/json'); // 设置企业微信自建应用的应用ID和应用密钥 HTTPClient.Request.CustomHeaders.Add('corpid: YOUR_CORPID'); HTTPClient.Request.CustomHeaders.Add('corpsecret: YOUR_CORPSECRET'); // 构建请求URL Response := HTTPClient.Get('https://qyapi.weixin.qq.com/cgi-bin/gettoken'); JSONData := TJSONObject.ParseJSONValue(Response) as TJSONObject; // 获取AccessToken AccessToken := JSONData.GetValue('access_token').Value; // 构建获取用户发来信息的请求URL Response := HTTPClient.Get(Format('https://qyapi.weixin.qq.com/cgi-bin/webhook/receive_message?access_token=%s', [AccessToken])); // 解析返回的JSON数据 JSONData := TJSONObject.ParseJSONValue(Response) as TJSONObject; JSONMessageArray := JSONData.GetValue('message')->JsonValue as TJSONArray; // 遍历消息数组 for i := 0 to JSONMessageArray.Count - 1 do begin MessageContent := JSONMessageArray.Items[i].GetValue('content').Value; // 在此处处理接收到的用户信息,可以根据需要进行相应的业务逻辑操作 // ... end; finally HTTPClient.Free; end; end; ``` 以上代码中,我们通过企业微信提供的接口获取AccessToken,然后构建请求URL,从中解析出用户发来的信息,最后进行相应的业务处理。 请注意,上述代码仅提供了一个基本的框架,具体的接口用和业务处理逻辑需要根据企业微信自建应用的实际情况进行相应的整和扩展。 ### 回答3: 在Delphi中通过企业微信自建应用接收用户发送的信息,可以使用企业微信提供的API接口来实现。下面是一个代码例子,演示了如何通过企业微信自建应用接收用户发送的信息: ```delphi uses IdHTTP, IdSSLOpenSSL, System.JSON; function ReceiveMessageFromWeChatApp(token, msgSignature, timestamp, nonce, postdata: string): string; var http: TIdHTTP; data, decryptedData, wechatMsg: string; begin http := TIdHTTP.Create; try http.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(http); http.AllowCookies := True; // 使用API接口校验消息的真实性 data := '{ "token":"' + token + '", "encodingAESKey":"' + encodingAESKey + '", "msgSignature":"' + msgSignature + '", "timestamp":"' + timestamp + '", "nonce":"' + nonce + '", "postdata":"' + postdata + '" }'; // 接收到的postdata需要进行解密处理,获取原始消息内容 decryptedData := DecryptData(data); // 解析得到的消息内容 wechatMsg := TJSONObject.ParseJSONValue(decryptedData).GetValue('Message').Value; // 做自定义的消息处理逻辑,例如回复消息 if wechatMsg = 'Hello' then Result := 'Welcome to our WeChat App!'; // 可以根据实际需求进行更多的消息处理 finally http.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); var token, msgSignature, timestamp, nonce, postdata: string; receivedMsg: string; begin token := 'your_wechat_app_token'; msgSignature := 'received_msg_signature'; timestamp := 'received_timestamp'; nonce := 'received_nonce'; postdata := 'received_post_data'; receivedMsg := ReceiveMessageFromWeChatApp(token, msgSignature, timestamp, nonce, postdata); ShowMessage(receivedMsg); end; ``` 在上述代码中,我们在`ReceiveMessageFromWeChatApp`函数中传入了从企业微信接收到的相关参数,包括`token`、`msgSignature`、`timestamp`、`nonce`和`postdata`,然后用企业微信提供的API接口进行校验消息真实性,获取并解析消息内容。最后,我们可以根据业务需要编写自定义的消息处理逻辑,在这个例子中我们对收到的消息进行了简单的判断,如果收到的消息是"Hello",则回复"Welcome to our WeChat App!"。具体的消息处理逻辑可以根据需求进行扩展和修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值