作者 lihan
1 个管道 的构建 通过 耗费 0 秒

支付宝

... ... @@ -20,46 +20,46 @@ use EasyWeChat\Foundation\Application;
class IndexController extends HomeBaseController
{
// function _initialize()
// {
// parent::_initialize(); // TODO: Change the autogenerated stub
// if (cmf_is_wechat()) {
// if (empty(session('user.id'))) {
// require_once EXTEND_PATH . '/WeChatCommon.php';
// $wx = new \WeChatCommon();
// if (request()->param('code') == NULL) {
// $wx->code();
// } else {
// $code = request()->param('code');
// $info = $wx->getOpenid($code);
// if (Db::name('user')->where(['openid' => $info['openid']])->count() == 0) {
// //注册新用户
// //拉去用户信息
// $return = $wx->getUserInfo($info);
// $data = [
// 'user_type' => 2,
// 'create_time' => time(),
// 'user_nickname' => $return['nickname'],
// 'sex' => $return['sex'],
// 'avatar' => $return['headimgurl'],
// 'openid' => $info['openid']
// ];
// if (Db::name('user')->insert($data)) {
// $userId = Db::name('user')->getLastInsID();
// session('user.id', $userId);
// session('user.openid', $info['openid']);
// }
// } else {
// $userId = Db::name('user')->where(['openid' => $info['openid']])->value('id');
// session('user.id', $userId);
// session('user.openid', $info['openid']);
// }
// }
// }
// } else {
// $this->error('请从微信浏览器打开');
// }
// }
function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
if (cmf_is_wechat()) {
if (empty(session('user.id'))) {
require_once EXTEND_PATH . '/WeChatCommon.php';
$wx = new \WeChatCommon();
if (request()->param('code') == NULL) {
$wx->code();
} else {
$code = request()->param('code');
$info = $wx->getOpenid($code);
if (Db::name('user')->where(['openid' => $info['openid']])->count() == 0) {
//注册新用户
//拉去用户信息
$return = $wx->getUserInfo($info);
$data = [
'user_type' => 2,
'create_time' => time(),
'user_nickname' => $return['nickname'],
'sex' => $return['sex'],
'avatar' => $return['headimgurl'],
'openid' => $info['openid']
];
if (Db::name('user')->insert($data)) {
$userId = Db::name('user')->getLastInsID();
session('user.id', $userId);
session('user.openid', $info['openid']);
}
} else {
$userId = Db::name('user')->where(['openid' => $info['openid']])->value('id');
session('user.id', $userId);
session('user.openid', $info['openid']);
}
}
}
} else {
$this->error('请从微信浏览器打开');
}
}
/**
* @title 接口返回参数说明
... ... @@ -191,12 +191,8 @@ class IndexController extends HomeBaseController
$payRequestBuilder->setTimeExpress($timeout_express);
$payResponse = new \AlipayTradeService($config);
if (cmf_is_wechat()) {
$result = $payResponse->wapPay($payRequestBuilder, $config['return_url'], $config['notify_url']);
} else {
$result = $payResponse->wapPay($payRequestBuilder, $config['return_url'], $config['notify_url']);
}
}
}
}
\ No newline at end of file
... ...