定制 hjp1011/yii2-easy-wechat 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hjp1011/yii2-easy-wechat

Composer 安装命令:

composer require hjp1011/yii2-easy-wechat

包简介

WeChat SDK for yii2, 基于 overtrue/easywechat

README 文档

README

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

WeChat SDK for Yii2 , Based on overtrue/wechat.
This extension makes it easy to use yii2 to call EasyWechat: Yii::$app->wechat.
Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Install

composer require hjp1011/yii2-easy-wechat

Config

Add SDK to Yii2 'config/main.php' component:

'components' => [
	// ...
	'wechat' => [
		'class' => 'yiiframe\easywechat\Wechat',
		'userOptions' => [],  // user identity class parameters
		'sessionParam' => 'wechatUser', // wechatUser information will be stored in the session in this key
		'returnUrlParam' => '_wechatReturnUrl', //returnUrl is stored in the session
		'rebinds' => [ // Customizable service module 
		    // 'cache' => 'common\components\Cache',
		]
	],
	// ...
]

Set basic configuration information and wechat payment information to 'config/params.php' :

// Wechat configuration details can refer to EasyWechat
'wechatConfig' => [],

// Wechat Pay configuration
'wechatPaymentConfig' => [],

// Micro channel applets configuration
'wechatMiniProgramConfig' => [],

// Wechat Open Platform Third-party platform configuration
'wechatOpenPlatformConfig' => [],

// Wechat enterprise wechat configuration
'wechatWorkConfig' => [],

// Wechat enterprise wechat open platform
'wechatOpenWorkConfig' => [],

// Wechat small and micro merchants
'wechatMicroMerchantConfig' => [],

The configuration document

Wechat configuration description document.
Wechat Pay configuration documentation.
Wechat applets configuration description document.
Wechat open Platform Third-party platform
Enterprise WeChat
Enterprise wechat open platform
Small businesses

Eample

Wechat web page authorization adn Get the current user information

if (Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) {
    return Yii::$app->wechat->authorizeRequired()->send();
}

// Method 1 to obtain the current user information of wechat
Yii::$app->session->get('wechatUser')

// Method 2 to obtain the current user information of wechat
Yii::$app->wechat->user

Obtain the wechat SDK instance

$app = Yii::$app->wechat->app;

Obtain the wechat Pay SDK instance

$payment = Yii::$app->wechat->payment;

Get the instance of wechat applets

$miniProgram = Yii::$app->wechat->miniProgram;

Obtain the third-party platform instance of wechat open Platform

$openPlatform = Yii::$app->wechat->openPlatform;

Obtain the enterprise wechat instance

$work = Yii::$app->wechat->work;

Access to wechat enterprise wechat open platform

$work = Yii::$app->wechat->openWork;

Get wechat small and micro merchants

$microMerchant = Yii::$app->wechat->microMerchant;

WeChat pay(JsApi):

// Pay parameters
$orderData = [ 
    'openid' => '.. '
    // ... etc. 
];

// Generate payment configuratio
$payment = Yii::$app->wechat->payment;
$result = $payment->order->unify($orderData);
if ($result['return_code'] == 'SUCCESS') {
    $prepayId = $result['prepay_id'];
    $config = $payment->jssdk->sdkConfig($prepayId);
} else {
    throw new yii\base\ErrorException('Wechat payment is abnormal, please try again later');
}  

return $this->render('wxpay', [
    'jssdk' => $payment->jssdk, // $app is retrieved from the above fetching instance
    'config' => $config
]);

JSSDK initiates payment

<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
    //Array for JSSDK authorization available methods, as needed to add a detailed view of wechat JSSDK methods
    wx.config(<?php echo $jssdk->buildConfig(array('chooseWXPay'), true) ?>);
    // Initiate payment
    wx.chooseWXPay({
        timestamp: <?= $config['timestamp'] ?>,
        nonceStr: '<?= $config['nonceStr'] ?>',
        package: '<?= $config['package'] ?>',
        signType: '<?= $config['signType'] ?>',
        paySign: '<?= $config['paySign'] ?>', // Pay for signature
        success: function (res) {
            // Callback function after successful payment
        }
    });
</script>

Smart tips

If you need an intelligent reminder from your editor (PhpStorm etc.) to use 'Yii::$app->wechat', add the following to 'Yii \ Base \Application' :

<?php

namespace yii\base;

use Yii;

/**
 *
 * @property \yiiframe\easywechat\Wechat $wechat Add this line to make the editor smart prompt.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
abstract class Application extends Module
{

}

More documentation

EasyWeChat Docs.

The instance

RageFrame

The problem of feedback

If you have any questions in use, please feel free to give me feedback. You can contact me through the following contact information

统计信息

  • 总下载量: 543
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固