get ready

1. Wechat service number   Corresponding   appId  and appsecret

2. Wechat payment merchant number Of ( Of merchant number id)  mch_id   ( Key for merchant payment )  key

Merchant's business key To check on wechat payment merchant platform

Start development

1.laravel install laravel/wechat

      Reference address

composer require "overtrue/laravel-wechat:~4.0"
        At the same time, we should pay attention to it laravel Of    csrf_token mechanism    

$officialAccount = EasyWeChat::officialAccount(); // Official account $work =
EasyWeChat::work(); // Examples of enterprise wechat $payment = EasyWeChat::payment(); // Wechat payment example
$openPlatform = EasyWeChat::openPlatform(); // Open platform example $miniProgram =
EasyWeChat::miniProgram(); // Applet instance The parameters of this instance are automatically from the config/wechat.php
Automatically obtained in the configuration file , Of course, you can specify it yourself


config/wechat.php The format of the file is shown in the figure below

Corresponding to the env Write in file   appid appsecret  mch_id   key  and token


Click payment initiated by the front end , Initiate payment request


Code for the page   ajax request wechat/prepay  address , Backstage plus config There are Adjust the parameters required for payment

Backstage wechat/pay The code for is as follows ,

there config It is an array of all the parameters in the front end

In this way, wechat payment is activated

It should be noted that , Wechat has regulations on the payment directory , It can be called only if it is in the specified directory

as : Configuration on wechat merchant platform What is the payment path for    ( Pay attention to the ending   “/”)

Then the path of our payment code should be In this path Subpath     as  It's OK to wait

You can't wait


Now the payment path configuration of wechat has been transferred to the merchant platform , Go and configure it yourself