Home > Back-end >  Want to convert WeChat public platform interface to DELPHI, the warrior to a train of thought
Want to convert WeChat public platform interface to DELPHI, the warrior to a train of thought

Time:09-29

Used in the development of database, rarely involves network,
Now you need to do a WeChat public platform to connect to the database development, have no idea, you look at the PHP example give a train of thought, whether can be realized,
The following is the PHP code:
<? PHP
/* *
* wechat PHP test
*/

//define your token
Define (" TOKEN ", "weixin");
$wechatObj=new wechatCallbackapiTest ();
$wechatObj - & gt; Valid ();

The class wechatCallbackapiTest
{
The public function valid ()
{
$echoStr=$_GET [" echoStr "];

//valid signature, option
If ($this - & gt; CheckSignature ()) {
Echo $echoStr;
exit;
}
}

The public function responseMsg ()
{
//get the post data, May be due to the company's environments
$postStr=$GLOBALS [" HTTP_RAW_POST_DATA "];

//extract post data
if (! Empty ($postStr)) {

$postObj=simplexml_load_string ($postStr, 'simplexmlelements, LIBXML_NOCDATA);
$fromUsername=$postObj - & gt; FromUserName;
$toUsername=$postObj - & gt; ToUserName;
$keyword=trim ($postObj - & gt; The Content);
$time=time();
$textTpl="& lt; Xml>


% s


0
";
if(! Empty ($keyword))
{
$msgType="text";
$contentStr="Welcome to wechat world!" ;
$resultStr=sprintf ($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
Echo $resultStr;
} else {
Echo "Input something... ";
}

} else {
Echo "";
exit;
}
}

Private function checkSignature ()
{
$signature=$_GET [" signature "];
$timestamp=$_GET [" timestamp "];
$nonce=$_GET [" nonce "];

$token=token;
$tmpArr=array($token, $timestamp, $nonce);
Sort ($tmpArr);
$tmpStr=the implode ($tmpArr);
$tmpStr=sha1 ($tmpStr);

If ($tmpStr==$signature) {
return true;
} else {
return false;
}
}
}

?>

I try to use IdHTTPServer control that can parse the POST data, no ideas behind, give a way of thinking that ace!

Thank you very much!

CodePudding user response:

Directly in PHP version, more convenient

CodePudding user response:

Yeah, why not use PHP

CodePudding user response:

IdHTTPServer?
General is the use of IdHTTPclient all send process simulation

CodePudding user response:

The building Lord, Delphi WeChat interface problem solved? I also need to this knowledge, give advice or comments please, thank you

CodePudding user response:

With q...

CodePudding user response:

WeChat interfaces are walking the HTTP protocol, has nothing to do with programming language, is nothing more than various HTTP requests,

CodePudding user response:

refer to 6th floor truexf response:
WeChat interface is the HTTP protocol, has nothing to do with programming language, is nothing more than various HTTP requests,

Well, the HTTP + JSON parsing, has nothing to do with programming language,

CodePudding user response:

I also in research.
Upstairs are all right, but no one method is given, but someone has made a similar online interface encapsulation
I look at the official PHP code examples, with Delphi WeChat platform the most it should be noted there should be two things:
One is in consistent coding problem
Second, sha1 function for authentication, in Delphi realize is not easy, is not usually in accordance with PHP generated
Other aspects have done HTTP communication should be easy to grasp the

Lots of interface encapsulation and fault processing, it is time-consuming, anyway I am to have no time to study, looking forward to your success

CodePudding user response:

Box has been made the example applications, is good

CodePudding user response:

I also doing minivan many members of the interface, made the HTTP server TIdHttpServer, however, found a cell phone and Internet explorer submit over packet (json format, tracking RequestInfo. ContentType='application/json. Charset=utf8 '), in OnCommandGet
RequestInfo FromParams receives the Chinese is garbled (?) , whether in UTF8Decode (RequestInfo FromParams)
Or directly to the RequestInfo FromParams displayed, are all garbled (?) And don't know how to solve?

I suspect that Delphi TIdHttpServer TIdHttp can only use for the client to submit? Exclude hope

CodePudding user response:

Attention,,,,,,,,

CodePudding user response:

Well, this I also watching
Hope to have substantial things out,

CodePudding user response:

Attention,,,, hope the success of sharing, let d have been living

CodePudding user response:

Use RTCClient components
  • Related