PHP code example of mxh861001 / wechat
1. Go to this page and download the library: Download mxh861001/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');
/* Start to develop here. Best regards https://php-download.com/ */
mxh861001 / wechat example snippets
'components' => [
// ...
'wechat' => [
'class' => 'mxh861001\easywechat\Wechat',
'rebinds' => [ // 自定义服务模块
// 'cache' => 'common\components\Cache',
]
],
// ...
]
// 微信配置 具体可参考EasyWechat
'wechatConfig' => [],
// 微信支付配置 具体可参考EasyWechat
'wechatPaymentConfig' => [],
// 微信小程序配置 具体可参考EasyWechat
'wechatMiniProgramConfig' => [],
$app = Yii::$app->wechat->app;
$payment = Yii::$app->wechat->payment;
$miniProgram = Yii::$app->wechat->miniProgram;
// 支付参数
$orderData = [
'openid' => '.. '
// ... etc.
];
// 生成支付配置
$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('微信支付异常, 请稍后再试');
}
return $this->render('wxpay', [
'jssdk' => $payment->jssdk, // $app通过上面的获取实例来获取
'config' => $config
]);
namespace yii\base;
use Yii;
/**
*
* @property \mxh861001\easywechat\Wechat $wechat 加入这一行即可实现编辑器智能提示.
*
*/
abstract class Application extends Module
{
}