2017 © Pedro Peláez
 

library yii2-wechat

WeChat SDK for yii2, based on overtrue/easywechat

image

elim051/yii2-wechat

WeChat SDK for yii2, based on overtrue/easywechat

  • Thursday, January 18, 2018
  • by elim051
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

yii2-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., (*1)

Installation

composer require elim051/yii2-wechat
或者将下边这个行代码加入到你的composer.json的require中
"elim051/yii2-wechat": "*"

Configuration

Add the SDK as a yii2 application component in the config/main.php:, (*2)


'components' => [ // ... 'wechat' => [ 'class' => 'elim051\easywechat\Wechat', 'config' => [ // easywechat configurations 'app_id' => 'wx3cf0f39249eb0exx', 'secret' => 'f1c242f4f28f735d4687abb469072axx', // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 'response_type' => 'array', 'log' => [ 'level' => 'debug', 'file' => __DIR__.'/wechat.log', ], ] // '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(); } // 自定义scopes if(Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) { Yii::$app->wechat->scopes = ['snsapi_userinfo']; 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 ]);

Wechat options configure help docs., (*3)

More documentation

see EasyWeChat Docs., (*4)

Thanks to overtrue/wechat , realy a easy way to play with wechat SDK 😁. Thanks to maxwen/yii2-easy-wechat 😁., (*5)

The Versions

18/01 2018

dev-master

9999999-dev

WeChat SDK for yii2, based on overtrue/easywechat

  Sources   Download

MIT

The Requires

 

by James.wang

18/01 2018

v0.2

0.2.0.0

WeChat SDK for yii2, based on overtrue/easywechat

  Sources   Download

MIT

The Requires

 

by James.wang

17/01 2018

v0.1

0.1.0.0

WeChat SDK for yii2, based on overtrue/easywechat

  Sources   Download

MIT

The Requires

 

by James.wang