Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the defects of ThinkPHP built-in jsonRPC

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to understand the defects of the built-in jsonRPC in ThinkPHP". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The specific analysis is as follows:

Recently in the development of ios applications, to develop ios applications, of course, to use the server, the server must choose the remote call protocol, because I have been developed with php, so I choose thinkphp as the apache server of the framework.

As for the remote call protocol, after thinking, or choose jsonRPC, it is relatively simple and convenient, turned to thinkphp (is version 3.2) of the manual, found that thinkphp still supports jsonRPC, which is good, do not have to write their own (of course, write their own is not a troublesome matter).

Simply, use thinkphp as a client to call the thinkphp server-side interface, easy to use.

Next is the Android end, casually go to the Internet to find an android-json-rpc.jar, call the interface, ah! It's easy to use, and it's going well.

Next, I changed the ios. I found an objc-JSONRpc project on the github and used it to call the interface. It was not easy to use, and it was normal. Maybe there was something wrong with the project I was looking for, so I changed a Demiurgic-JSON-RPC, but it was still not easy to use. I began to have doubts about the program, because there was no problem with both the web end and the android side, so I focused on my ios program. Oh, my God, it took me a long time, but I just didn't find the problem. I also used iOS to call the jsp client interface provided by others, no problem.

Later, I began to look at the jsonRPC module built into thinkphp, and after constant debugging (various debugging, deleting code, and Dbug), I found this line of code:

The copy code is as follows:

$result = @ call_user_func_array (array ($object,$request ['method']), $request [' params'])

Notice this function, call_user_func_array,array, click to see the parameter description, sure enough, $request ['params'] must be an array type, not the array does not recognize, more hateful is that thinkphp does not have a strict check on this parameter, so do not know how wrong.

It will be easy to know this reason, with a check in front of it.

The copy code is as follows:

If (is_array ($request ['params'])) {

$request ['params'] = array_values ($request [' params'])

} else {

$request ['params'] = array ($request [' params'])

}

This is the end of the content of "how to understand the defects of ThinkPHP's built-in jsonRPC". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report