This article mainly introduces in detail the relevant information on the simple implementation of translation in PHP WeChat development. Interested friends can refer to it. I hope to be helpful.
First of all, you need to go to the official website of Youdao Translation API to apply for a key: http://fanyi.youdao.com/openapi?path=data-mode
After getting the key, you can start to use the API The queried data is obtained (return json or XML, depending on personal preference, I use json here)
Below I will directly give the code to implement translation in the responseMsg method. If you are coming into contact with the WeChat API for the first time and don’t understand what this method does, please click on PHP WeChat Development Text Automatic Reply
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
Note: The information returned by the subscription account you are following needs to be line-wrapped, and you must use " \n". In your website space, modify your code and send a message such as "Translation Hamburger" to the subscription account. The subscription account will call Youdao's API to return the translation result, which can be translated between Chinese and English, or it can be a sentence.
Related recommendations:
How to verify token, reply content, and push messages for WeChat public account in PHP
PHP WeChat development to obtain city weather
WeChat development template message reply
The above is the detailed content of Translation function developed by PHP WeChat. For more information, please follow other related articles on the PHP Chinese website!