yii2-easy-wechat

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

Github星跟蹤圖

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 ]
微信选项配置帮助文档

主要指標

概覽
名稱與所有者imaxwen/yii2-easy-wechat
主編程語言PHP
編程語言PHP (語言數: 1)
平台Linux, Mac, Windows, 微信公众平台
許可證MIT License
所有者活动
創建於2016-10-25 06:14:54
推送於2017-10-18 03:56:10
最后一次提交2017-08-11 13:09:15
發布數8
最新版本名稱1.0.3 (發布於 )
第一版名稱0.9 (發布於 )
用户参与
星數187
關注者數12
派生數57
提交數20
已啟用問題?
問題數16
打開的問題數6
拉請求數1
打開的拉請求數0
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

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