YII2-WX Installation and upgrade

Source: Internet
Author: User
The reason for this extension is that there is no mature and maintained SDK in the YII2 framework so far, and as each backend person, development may not be possible to bypass. So in 2017 the PHP Academy opened a course called "building an open source SDK" and promised to open it up after the course was completed, which was the predecessor of YII2-WX.
Of course, the YII2-WX has a more powerful function at the moment, in addition to supporting the public interface It also supports small programs, open platform (later version open) and so on. YII2-WX Hosting Platform

Installing with composer

You can use composer to install and upgrade automatically, North Brother also recommend you do so.

Composer require "Abei2017/yii2-wx"

If there is a problem with composer, please add the-VVV parameter later, so you can see the specific error message.

Composer require "abei2017/yii2-wx"-VVV

After the installation is successful, the YII2-WX is stored in the program's vendor/abei2017 folder.

Manual Installation

If your environment is not able to use composer that's OK, you can go to download page download the corresponding version after the manual deployment, the steps are as follows:

    1. Unzip the installation package into a program directory (e.g. create a new ext folder)

    2. Open Yii2 config/web.php file to add an alias

' Aliases ' = [
' abei2017/wx ' = ' @app/ext/yii2-wx/src ',
],

Reminder: Aliases and components are the same level, do not put the wrong. The primary purpose of our use of aliases is to have a normal reference.

Directory structure

Whether it is automatic or manual installation, the YII2-WX directory structure is the same, as follows

Yii2-wx
-SRC
--core//kernel file
--helpers//Help file
--Mini//applet interface
--MP//Public number interface
--application.php//import file
-Composer.json
-Readme.md

Configuration

Follow the steps above and you have successfully installed YII2-WX into your YII2 program, which we need to configure before using.

' WX ' =>[
Public number information
' MP ' =>[
/**
* Account basic information, please from public platform
*/
' app_id ' and ' = ',//AppID
' Secret ' and ' = ',//Appsecret
' token ' = ', '//token
' Encodingaeskey ' = ',
' SafeMode ' =>0

' Payment ' =>[
' mch_id ' = ',
' Key ' = ',
' Notify_url ' = ',
' Cert_path ' = ', '//XXX: absolute path!!!!
' Key_path ' = ', '//XXX: absolute path!!!!
],

' OAuth ' = [
' Scopes ' = ' snsapi_userinfo ',
' Callback ' = ',
],
],
' Mini ' =>[
' app_id ' = ',
' Secret ' = ',
' Payment ' = [
' mch_id ' = ',
' Key ' = '
],
]
],

You just have to make sure that the keys in the Mini and MP arrays are the same. For example, now I want to generate a temporary QR code, can be the following code

$app = new Application ([' Conf ' =>yii:: $app->params[' WX ' [' MP ']]);
$qrcode = $app->driver ("Mp.qrcode");

$result = $qrcode->inttemp (3600,9527);

In this way, we always instantiate a application and pass the parameters (public number/applet), then use driver to drive the object of the corresponding interface and use the corresponding method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.