PHP code example of mejinke / wechat
1. Go to this page and download the library: Download mejinke/wechat library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
mejinke / wechat example snippets
$options = [
'appid' => 'xx' ,
'appsecret' => 'xx' ,
'mchid' => 'xx' ,
'key' => 'xx'
];
$wechat = new \Wechat\Wechat($options);
$event = $wechat->service('Event' );
$event->subscribe(function (\Wechat\Component\Event $e) {
});
$event->unsubscribe(function (\Wechat\Component\Event $e) {
});
$event->scan(function (\Wechat\Component\Event $e) {
});
$event->location(function (\Wechat\Component\Event $e) {
});
$event->dispatch();
$order = new \Wechat\Component\PayOrder();
$order->setBody("xxxxx" );
$order->setAttach("xxxx" );
$order->setOutTradeNo("xxxxx" );
$order->setTotalFee(10 * 100 );
$order->setTimeStart(date("YmdHis" ));
$order->setTimeExpire(date("YmdHis" , time() + 600 ));
$order->setTradeType('JSAPI' );
$order->setOpenid("xxxxx" );
$pay = $wechat->service('Pay' );
$result = $pay->createOrder($order);
$pay->getJsApiParameters($result);
$pay->notifyProcess(function ($data) {
});
$menu = new \Wechat\Component\Menu();
$id = $menu->addViewButton('官网' , 'http://www.xxxx.com' );
$menu->addViewButton('主页' , 'http://www.xxxx.com' , $id);
$menu->addClickButton('最新' , 'news' );
$wechat->service('Menu' )->create($menu);