yii2-easy-wechat

基于 overtrue/wechat 的 yii2 微信 SDK。(WeChat SDK for yii2 , based on overtrue/wechat.)

Github stars Tracking Chart

yii2-easy-wechat

基于 overtrue/wechat 的 yii2 微信 SDK。

此扩展程序可帮助您以简单熟悉的方式访问 overtrue/wechat 应用程序:Yii::$app->wechat。

安装

composer require maxwen/yii2-easy-wechat

配置

在 config/main.php 中将 SDK 添加为 yii2 应用程序组件:

'components' => [
    // ...
    'wechat' => [
        'class' => 'maxwen\easywechat\Wechat',
        // 'userOptions' => []  # user identity class params
        // 'sessionParam' => '' # wechat user info will be stored in session under this key
        // 'returnUrlParam' => '' # returnUrl param stored in session
    ],
    // ...
]

使用

// here are two representative examples that will help you:
// 微信网页授权:
if(Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) {
    return Yii::$app->wechat->authorizeRequired()->send();
}
// 微信支付(JsApi):
$orderData = [ 
    'openid' => '.. '
    // ... etc. 
];
$order = new WechatOrder($orderData);
$payment = Yii::$app->wechat->payment;
$prepayRequest = $payment->prepare($order);
if($prepayRequest->return_code = 'SUCCESS' && $prepayRequest->result_code == 'SUCCESS') {
    $prepayId = $prepayRequest->prepay_id;
}else{
    throw new yii\base\ErrorException('微信支付异常, 请稍后再试');
}
$jsApiConfig = $payment->configForPayment($prepayId);
return $this->render('wxpay', [
    'jsApiConfig' => $jsApiConfig,
    'orderData'   => $orderData
]);

如何加载微信配置?

overrue/wechat 应用程序总是使用 $options 参数构造。 我在 params.php 中将选项作为 yii2 param:

推荐方式:

// in this way you need to create a wechat.php in the same directory of params.php
// put contents in the wechat.php like:
// return [ 
//         // wechat options here 
// ];
'WECHAT' => require(__DIR__.'/wechat.php'),
或者
'WECHAT' => [ // wechat options here ]
微信选项配置帮助文档

Main metrics

Overview
Name With Ownerimaxwen/yii2-easy-wechat
Primary LanguagePHP
Program languagePHP (Language Count: 1)
PlatformLinux, Mac, Windows, 微信公众平台
License:MIT License
所有者活动
Created At2016-10-25 06:14:54
Pushed At2017-10-18 03:56:10
Last Commit At2017-08-11 13:09:15
Release Count8
Last Release Name1.0.3 (Posted on )
First Release Name0.9 (Posted on )
用户参与
Stargazers Count187
Watchers Count12
Fork Count57
Commits Count20
Has Issues Enabled
Issues Count16
Issue Open Count6
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

yii2-easy-wechat

WeChat SDK for yii2 , based on overtrue/wechat.
This extension helps you access overtrue/wechat application in a simple & familiar way: Yii::$app->wechat.

Latest Stable Version
Total Downloads
License

Installation

composer require maxwen/yii2-easy-wechat

Configuration

Add the SDK as a yii2 application component in the config/main.php:


'components' => [
	// ...
	'wechat' => [
		'class' => 'maxwen\easywechat\Wechat',
		// 'userOptions' => []  # user identity class params
		// 'sessionParam' => '' # wechat user info will be stored in session under this key
		// 'returnUrlParam' => '' # returnUrl param stored in session
	],
	// ...
]

Usage


// here are two representative examples that will help you:

// 微信网页授权:
if(Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) {
	return Yii::$app->wechat->authorizeRequired()->send();
}

// 微信支付(JsApi):
$orderData = [ 
	'openid' => '.. '
	// ... etc. 
];
$order = new WechatOrder($orderData);
$payment = Yii::$app->wechat->payment;
$prepayRequest = $payment->prepare($order);
if($prepayRequest->return_code = 'SUCCESS' && $prepayRequest->result_code == 'SUCCESS') {
	$prepayId = $prepayRequest->prepay_id;
}else{
	throw new yii\base\ErrorException('微信支付异常, 请稍后再试');
}

$jsApiConfig = $payment->configForPayment($prepayId);

return $this->render('wxpay', [
	'jsApiConfig' => $jsApiConfig,
	'orderData'   => $orderData
]);

How to load Wechat configures?

the overtrue/wechat application always constructs with a $options parameter.
I made the options as a yii2 param in the params.php:

recomended way:

// in this way you need to create a wechat.php in the same directory of params.php
// put contents in the wechat.php like:
// return [ 
// 		// wechat options here 
// ];
'WECHAT' => require(__DIR__.'/wechat.php'),

OR

'WECHAT' => [ // wechat options here ]

Wechat options configure help docs.

More documentation

see EasyWeChat Docs.

Thanks to overtrue/wechat , realy a easy way to play with wechat SDK ?.

More repos for Yii2:

yii2-ckeditor-widget
yii2-adminlte-gii
yii2-curl