140 行
5.4 KiB
PHP
可执行文件
140 行
5.4 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Vip\Controller;
|
|
|
|
use Common\Business\PaySet;
|
|
use Common\Business\XcxUser;
|
|
use Think\Controller;
|
|
use Think\Jssdk;
|
|
|
|
//[1.7.90]
|
|
|
|
/**
|
|
* 微信服务商模式公众号授权-目前仅商家券及代金券使用
|
|
* Class CouponAuthController
|
|
* @package Vip\Controller
|
|
*/
|
|
class CouponAuthController extends Controller
|
|
{
|
|
public static $SET;//全局静态配置
|
|
protected static $_wxappid;
|
|
protected static $_wxappsecret;
|
|
|
|
Public function _initialize()
|
|
{
|
|
$xcx_id = I('get.xcx_id');
|
|
$user_type = I('get.user_type');
|
|
$PaySetClass = new PaySet();
|
|
$payResult = $PaySetClass->getServiceSet([
|
|
'xcx_id' => $xcx_id,
|
|
'user_type' => $user_type //1普通支付模式 2服务商支付模式
|
|
]); //获取支付参数
|
|
if ($payResult['status'] != 1) {
|
|
$this->error(0, $payResult['message']);
|
|
}
|
|
if (I('get.page')) {
|
|
session('page', I('get.page'));
|
|
}
|
|
self::$SET = $_SESSION['SET'] = $payResult['data']['paySet'];
|
|
$title = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
|
|
$_url = $title . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
// 用户自定义配置微信公众号
|
|
self::$_wxappid = self::$SET['appid'];
|
|
self::$_wxappsecret = self::$SET['appsecret'];
|
|
if ($user_type == 1 && self::$SET['type'] == 2) {
|
|
//第三方授权微信公众号
|
|
$appinfo = M('appweixin')->where('id = 1')->find();
|
|
$options['appid'] = self::$SET['authorizer_appid'];
|
|
if (strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")) {
|
|
//判断code是否存在
|
|
if ($_GET['code']) {
|
|
if ($_GET['code'] != 'authdeny') {
|
|
$wx = new \Util\Wx\Wechat($options);
|
|
$token = get_acc_token();
|
|
$re = $wx->getOauthAccessTokens($_GET['code'], $appinfo['appid'], $token);//获取access_token和openid
|
|
if ($re) {
|
|
$_SESSION['openid'] = $re['openid'];
|
|
}
|
|
} else {
|
|
$this->tipsMsg(0, '本应用需要您的授权才可以使用!');
|
|
}
|
|
} else {
|
|
$wx = new \Util\Wx\Wechat($options);
|
|
$squrl = $wx->getOauthRedirects($_url, '1', 'snsapi_base', $appinfo['appid']);
|
|
header("Location:" . $squrl);
|
|
exit;
|
|
}
|
|
} else {
|
|
$this->tipsMsg(0, '请使用微信浏览器访问本应用!');
|
|
}
|
|
} else {
|
|
if (strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")) {
|
|
//判断code是否存在
|
|
if ($_GET['code']) {
|
|
if ($_GET['code'] != 'authdeny') {
|
|
//用户授权
|
|
$options['appid'] = self::$_wxappid;
|
|
$options['appsecret'] = self::$_wxappsecret;
|
|
$wx = new \Util\Wx\Wechat($options);
|
|
$re = $wx->getOauthAccessToken($_GET['code']);//
|
|
$openid = $re['openid'];
|
|
if ($re) {
|
|
$_SESSION['openid'] = $openid;
|
|
}
|
|
} else {
|
|
$this->error(0, '本应用需要您的授权才可以使用!');
|
|
}
|
|
} else {
|
|
$options['appid'] = self::$_wxappid;
|
|
$options['appsecret'] = self::$_wxappsecret;
|
|
$wx = new \Util\Wx\Wechat($options);
|
|
$squrl = $wx->getOauthRedirect($_url, '1', 'snsapi_base');
|
|
header("Location:" . $squrl);
|
|
exit;
|
|
}
|
|
} else {
|
|
$this->error('请使用微信浏览器访问本应用!');
|
|
}
|
|
}
|
|
$this->getJssdk();
|
|
}
|
|
|
|
//生成微信jssdk 参数 ,用于页面展示图片和分享链接
|
|
public function getJssdk()
|
|
{
|
|
self::$_wxappid = self::$SET['appid'];
|
|
self::$_wxappsecret = self::$SET['appsecret'];
|
|
$jssdk = new Jssdk(self::$_wxappid, self::$_wxappsecret);
|
|
$signPackage = $jssdk->GetSignPackage();
|
|
$this->assign('signPackage', $signPackage);
|
|
}
|
|
|
|
/**
|
|
* 微信券服务商授权
|
|
*
|
|
*/
|
|
public function couponAuth()
|
|
{
|
|
$user_type = I('get.user_type'); //1普通支付模式 2服务商支付模式
|
|
$xcx_id = I('get.xcx_id');
|
|
$openid = session('openid');
|
|
if (empty($user_type)) {
|
|
return callBack(statusCode()['error'], "请选择授权模式");
|
|
}
|
|
if (empty($xcx_id)) {
|
|
return callBack(statusCode()['error'], "请先在小程序授权");
|
|
}
|
|
if (empty($openid)) {
|
|
return callBack(statusCode()['error'], "请授权公众号");
|
|
}
|
|
$param = [
|
|
'xcx_id' => $xcx_id,
|
|
'openid' => $openid,
|
|
'user_type' => $user_type
|
|
];
|
|
$xcxUserClass = new XcxUser();
|
|
$xcxUserClass->modifyServiceOpenid($param);
|
|
$this->assign('page', session('page'));
|
|
$this->display();
|
|
}
|
|
} |