user
parent
58cbeffadc
commit
aa0e11e678
|
|
@ -3,6 +3,7 @@
|
|||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
padding-bottom: 120rpx;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.content-items {
|
||||
float: left;
|
||||
|
|
@ -15,6 +16,6 @@
|
|||
line-height: 46rpx;
|
||||
}
|
||||
.content-items .icon {
|
||||
width: 120rpx;
|
||||
width: 100%;
|
||||
height: 120rpx;
|
||||
}
|
||||
|
|
@ -6,16 +6,33 @@
|
|||
<!-- form start -->
|
||||
<form class="am-form form-validation view-save" action="{{:U('Admin/AppMiniAlipayConfig/Save')}}" method="POST" request-type="ajax-url" request-value="{{:U('Admin/AppMiniAlipayConfig/Index')}}">
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.home_app_mini_alipay_title.name}}</label>
|
||||
<input type="text" name="{{$data.home_app_mini_alipay_title.only_tag}}" placeholder="{{$data.home_app_mini_alipay_title.name}}" data-validation-message="{{$data.home_app_mini_alipay_title.error_tips}}" class="am-radius" <present name="data"> value="{{$data.home_app_mini_alipay_title.value}}"</present> required />
|
||||
<label>{{$data.common_app_mini_alipay_appid.name}}</label>
|
||||
<input type="text" name="{{$data.common_app_mini_alipay_appid.only_tag}}" placeholder="{{$data.common_app_mini_alipay_appid.name}}" data-validation-message="{{$data.common_app_mini_alipay_appid.error_tips}}" class="am-radius" <present name="data"> value="{{$data.common_app_mini_alipay_appid.value}}"</present> required />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.home_app_mini_alipay_describe.name}}</label>
|
||||
<input type="text" name="{{$data.home_app_mini_alipay_describe.only_tag}}" placeholder="{{$data.home_app_mini_alipay_describe.name}}" data-validation-message="{{$data.home_app_mini_alipay_describe.error_tips}}" class="am-radius" <present name="data"> value="{{$data.home_app_mini_alipay_describe.value}}"</present> required />
|
||||
<label>{{$data.common_app_mini_alipay_rsa_public.name}}</label>
|
||||
<textarea rows="3" name="{{$data.common_app_mini_alipay_rsa_public.only_tag}}" class="am-radius" placeholder="{{$data.common_app_mini_alipay_rsa_public.name}}" data-validation-message="{{$data.common_app_mini_alipay_rsa_public.error_tips}}"><present name="data">{{$data.common_app_mini_alipay_rsa_public.value}}</present></textarea>
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.home_app_mini_alipay_customer_service_tel.name}}</label>
|
||||
<input type="text" name="{{$data.home_app_mini_alipay_customer_service_tel.only_tag}}" placeholder="{{$data.home_app_mini_alipay_customer_service_tel.name}}" data-validation-message="{{$data.home_app_mini_alipay_customer_service_tel.error_tips}}" class="am-radius" <present name="data"> value="{{$data.home_app_mini_alipay_customer_service_tel.value}}"</present> />
|
||||
<label>{{$data.common_app_mini_alipay_rsa_private.name}}</label>
|
||||
<textarea rows="3" name="{{$data.common_app_mini_alipay_rsa_private.only_tag}}" class="am-radius" placeholder="{{$data.common_app_mini_alipay_rsa_private.name}}" data-validation-message="{{$data.common_app_mini_alipay_rsa_private.error_tips}}"><present name="data">{{$data.common_app_mini_alipay_rsa_private.value}}</present></textarea>
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.common_app_mini_alipay_out_rsa_public.name}}</label>
|
||||
<textarea rows="3" name="{{$data.common_app_mini_alipay_out_rsa_public.only_tag}}" class="am-radius" placeholder="{{$data.common_app_mini_alipay_out_rsa_public.name}}" data-validation-message="{{$data.common_app_mini_alipay_out_rsa_public.error_tips}}"><present name="data">{{$data.common_app_mini_alipay_out_rsa_public.value}}</present></textarea>
|
||||
</div>
|
||||
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.common_app_mini_alipay_title.name}}</label>
|
||||
<input type="text" name="{{$data.common_app_mini_alipay_title.only_tag}}" placeholder="{{$data.common_app_mini_alipay_title.name}}" data-validation-message="{{$data.common_app_mini_alipay_title.error_tips}}" class="am-radius" <present name="data"> value="{{$data.common_app_mini_alipay_title.value}}"</present> required />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.common_app_mini_alipay_describe.name}}</label>
|
||||
<input type="text" name="{{$data.common_app_mini_alipay_describe.only_tag}}" placeholder="{{$data.common_app_mini_alipay_describe.name}}" data-validation-message="{{$data.common_app_mini_alipay_describe.error_tips}}" class="am-radius" <present name="data"> value="{{$data.common_app_mini_alipay_describe.value}}"</present> required />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{$data.common_app_mini_alipay_customer_service_tel.name}}</label>
|
||||
<input type="text" name="{{$data.common_app_mini_alipay_customer_service_tel.only_tag}}" placeholder="{{$data.common_app_mini_alipay_customer_service_tel.name}}" data-validation-message="{{$data.common_app_mini_alipay_customer_service_tel.error_tips}}" class="am-radius" <present name="data"> value="{{$data.common_app_mini_alipay_customer_service_tel.value}}"</present> />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm w100" data-am-loading="{loadingText:'{{:L('common_form_loading_tips')}}'}">{{:L('common_operation_save')}}</button>
|
||||
|
|
|
|||
|
|
@ -11,70 +11,70 @@ namespace Api\Controller;
|
|||
*/
|
||||
class UserController extends CommonController
|
||||
{
|
||||
/**
|
||||
* [_initialize 前置操作-继承公共前置方法]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-02T22:48:35+0800
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
// 调用父类前置方法
|
||||
parent::_initialize();
|
||||
/**
|
||||
* [_initialize 前置操作-继承公共前置方法]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-02T22:48:35+0800
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
// 调用父类前置方法
|
||||
parent::_initialize();
|
||||
|
||||
// 是否ajax请求
|
||||
if(!IS_AJAX)
|
||||
{
|
||||
$this->error(L('common_unauthorized_access'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Reg 用户注册-数据添加]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-07T00:08:36+0800
|
||||
*/
|
||||
public function Reg()
|
||||
{
|
||||
// 账户校验
|
||||
$this->UserRegAccountsCheck();
|
||||
/**
|
||||
* [Reg 用户注册-数据添加]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-07T00:08:36+0800
|
||||
*/
|
||||
public function Reg()
|
||||
{
|
||||
// 账户校验
|
||||
$this->UserRegAccountsCheck();
|
||||
|
||||
// 验证码校验
|
||||
$verify_param = array(
|
||||
'key_prefix' => 'reg',
|
||||
'expire_time' => MyC('common_verify_expire_time')
|
||||
);
|
||||
$obj = new \Library\Sms($verify_param);
|
||||
// 验证码校验
|
||||
$verify_param = array(
|
||||
'key_prefix' => 'reg',
|
||||
'expire_time' => MyC('common_verify_expire_time')
|
||||
);
|
||||
$obj = new \Library\Sms($verify_param);
|
||||
|
||||
// 是否已过期
|
||||
if(!$obj->CheckExpire())
|
||||
{
|
||||
$this->ajaxReturn(L('common_verify_expire'), -10);
|
||||
}
|
||||
// 是否正确
|
||||
if(!$obj->CheckCorrect(I('verify')))
|
||||
{
|
||||
$this->ajaxReturn(L('common_verify_error'), -11);
|
||||
}
|
||||
// 是否已过期
|
||||
if(!$obj->CheckExpire())
|
||||
{
|
||||
$this->ajaxReturn(L('common_verify_expire'), -10);
|
||||
}
|
||||
// 是否正确
|
||||
if(!$obj->CheckCorrect(I('verify')))
|
||||
{
|
||||
$this->ajaxReturn(L('common_verify_error'), -11);
|
||||
}
|
||||
|
||||
// 绑定
|
||||
$m = M('User');
|
||||
// 绑定
|
||||
$m = M('User');
|
||||
$type_field = I('app_type', 'alipay').'_openid';
|
||||
$data = array(
|
||||
$type_field => I('alipay_openid'),
|
||||
'mobile' => I('mobile'),
|
||||
$data = array(
|
||||
$type_field => I($type_field),
|
||||
'mobile' => I('mobile'),
|
||||
'referrer' => intval(I('referrer', 0)),
|
||||
'nickname' => I('nickname'),
|
||||
'avatar' => I('avatar'),
|
||||
'province' => I('province'),
|
||||
'city' => I('city'),
|
||||
'gender' => intval(I('gender', 0)),
|
||||
);
|
||||
);
|
||||
|
||||
$where = [$type_field=>I('alipay_openid'), 'is_delete_time'=>0];
|
||||
$where = ['mobile'=>$data['mobile'], 'is_delete_time'=>0];
|
||||
$temp = $m->where($where)->find();
|
||||
if(empty($temp))
|
||||
{
|
||||
|
|
@ -87,97 +87,91 @@ class UserController extends CommonController
|
|||
$user_id = $temp['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($user_id) && $user_id > 0)
|
||||
{
|
||||
// 清除验证码
|
||||
$obj->Remove();
|
||||
|
||||
if(isset($user_id) && $user_id > 0)
|
||||
{
|
||||
// 清除验证码
|
||||
$obj->Remove();
|
||||
|
||||
$this->ajaxReturn(L('common_bind_success'), 0, $m->find($user_id));
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_bind_error'), -100);
|
||||
}
|
||||
}
|
||||
$this->ajaxReturn(L('common_bind_success'), 0, $m->find($user_id));
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_bind_error'), -100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [RegVerifySend 用户注册-验证码发送]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-05T19:17:10+0800
|
||||
*/
|
||||
public function RegVerifySend()
|
||||
{
|
||||
// 账户校验
|
||||
$this->UserRegAccountsCheck();
|
||||
/**
|
||||
* [RegVerifySend 用户注册-验证码发送]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-05T19:17:10+0800
|
||||
*/
|
||||
public function RegVerifySend()
|
||||
{
|
||||
// 账户校验
|
||||
$this->UserRegAccountsCheck();
|
||||
|
||||
// 验证码公共基础参数
|
||||
$verify_param = array(
|
||||
'key_prefix' => 'reg',
|
||||
'expire_time' => MyC('common_verify_expire_time'),
|
||||
'time_interval' => MyC('common_verify_time_interval'),
|
||||
);
|
||||
// 验证码公共基础参数
|
||||
$verify_param = array(
|
||||
'key_prefix' => 'reg',
|
||||
'expire_time' => MyC('common_verify_expire_time'),
|
||||
'time_interval' => MyC('common_verify_time_interval'),
|
||||
);
|
||||
|
||||
// 发送验证码
|
||||
$obj = new \Library\Sms($verify_param);
|
||||
$code = GetNumberCode(6);
|
||||
$status = $obj->SendCode(I('mobile'), $code, MyC('home_sms_user_reg'));
|
||||
|
||||
// 状态
|
||||
if($status)
|
||||
{
|
||||
$this->ajaxReturn(L('common_send_success'), 0);
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_send_error').'['.$obj->error.']', -100);
|
||||
}
|
||||
}
|
||||
// 发送验证码
|
||||
$obj = new \Library\Sms($verify_param);
|
||||
$code = GetNumberCode(6);
|
||||
$status = $obj->SendCode(I('mobile'), $code, MyC('home_sms_user_reg'));
|
||||
|
||||
// 状态
|
||||
if($status)
|
||||
{
|
||||
$this->ajaxReturn(L('common_send_success'), 0);
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_send_error').'['.$obj->error.']', -100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [UserRegAccountsCheck 用户注册账户校验]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-10T10:06:29+0800
|
||||
*/
|
||||
private function UserRegAccountsCheck()
|
||||
{
|
||||
// 参数
|
||||
$accounts = I('mobile');
|
||||
if(empty($accounts))
|
||||
{
|
||||
$this->ajaxReturn(L('common_param_error'), -1);
|
||||
}
|
||||
/**
|
||||
* [UserRegAccountsCheck 用户注册账户校验]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-10T10:06:29+0800
|
||||
*/
|
||||
private function UserRegAccountsCheck()
|
||||
{
|
||||
// 参数
|
||||
$accounts = I('mobile');
|
||||
if(empty($accounts))
|
||||
{
|
||||
$this->ajaxReturn(L('common_param_error'), -1);
|
||||
}
|
||||
|
||||
// 手机号码格式
|
||||
if(!CheckMobile($accounts))
|
||||
{
|
||||
$this->ajaxReturn(L('common_mobile_format_error'), -2);
|
||||
}
|
||||
// 手机号码格式
|
||||
if(!CheckMobile($accounts))
|
||||
{
|
||||
$this->ajaxReturn(L('common_mobile_format_error'), -2);
|
||||
}
|
||||
}
|
||||
|
||||
// 手机号码是否已存在
|
||||
if($this->IsExistAccounts($accounts, 'mobile'))
|
||||
{
|
||||
$this->ajaxReturn(L('common_mobile_exist_error'), -3);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* [IsExistAccounts 账户是否存在]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-08T10:27:14+0800
|
||||
* @param [string] $accounts [账户名称]
|
||||
* @param [string] $field [字段名称]
|
||||
* @return [boolean] [存在true, 不存在false]
|
||||
*/
|
||||
private function IsExistAccounts($accounts, $field = 'mobile')
|
||||
{
|
||||
$id = M('User')->where(array('is_delete_time'=>0, $field=>$accounts))->getField('id');
|
||||
return !empty($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* [IsExistAccounts 账户是否存在]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-03-08T10:27:14+0800
|
||||
* @param [string] $accounts [账户名称]
|
||||
* @param [string] $field [字段名称]
|
||||
* @return [boolean] [存在true, 不存在false]
|
||||
*/
|
||||
private function IsExistAccounts($accounts, $field = 'mobile')
|
||||
{
|
||||
$id = M('User')->where(array('is_delete_time'=>0, $field=>$accounts))->getField('id');
|
||||
return !empty($id);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* [GetAlipayUserInfo 获取支付宝用户信息]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
|
|
@ -186,38 +180,49 @@ class UserController extends CommonController
|
|||
*/
|
||||
public function GetAlipayUserInfo()
|
||||
{
|
||||
$result = (new \Library\Alipay())->GetAlipayUserInfo(I('authcode'), C('alipay_mini_appid'));
|
||||
$result = (new \Library\Alipay())->GetAlipayUserInfo(I('authcode'), MyC('common_app_mini_alipay_appid'));
|
||||
if($result === false)
|
||||
{
|
||||
$this->ajaxReturn('获取授权信息失败');
|
||||
} else {
|
||||
$data = [
|
||||
'alipay_openid' => $result['user_id'],
|
||||
'nickname' => empty($result['nick_name']) ? '' : $result['nick_name'],
|
||||
'avatar' => empty($result['avatar']) ? '' : $result['avatar'],
|
||||
'gender' => empty($result['gender']) ? 0 : ($result['gender'] == 'm') ? 2 : 1,
|
||||
'province' => empty($result['province']) ? '' : $result['province'],
|
||||
'city' => empty($result['city']) ? '' : $result['city'],
|
||||
'referrer' => intval(I('referrer', 0)),
|
||||
];
|
||||
$m = M('User');
|
||||
$where = ['alipay_openid'=>$result['user_id'], 'is_delete_time'=>0];
|
||||
$user = $m->where($where)->find();
|
||||
if(!empty($user))
|
||||
{
|
||||
$data['upd_time'] = time();
|
||||
if($m->where($where)->save($data) === false)
|
||||
{
|
||||
$this->ajaxReturn('用户更新失败');
|
||||
}
|
||||
$data = $user;
|
||||
}
|
||||
|
||||
// 返回成功
|
||||
$this->ajaxReturn('授权成功', 0, $data);
|
||||
$result['openid'] = $result['user_id'];
|
||||
$this->AuthUserProgram($result, 'alipay_openid');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户授权保存
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-11-06
|
||||
* @desc description
|
||||
* @param [array] $params [用户数据]
|
||||
* @param [string] $field [平台字段名称]
|
||||
*/
|
||||
private function AuthUserProgram($params, $field)
|
||||
{
|
||||
$data = [
|
||||
$field => $params['openid'],
|
||||
'nickname' => empty($params['nick_name']) ? '' : $params['nick_name'],
|
||||
'avatar' => empty($params['avatar']) ? '' : $params['avatar'],
|
||||
'gender' => empty($params['gender']) ? 0 : ($params['gender'] == 'm') ? 2 : 1,
|
||||
'province' => empty($params['province']) ? '' : $params['province'],
|
||||
'city' => empty($params['city']) ? '' : $params['city'],
|
||||
'referrer' => intval(I('referrer', 0)),
|
||||
];
|
||||
$m = M('User');
|
||||
$where = [$field=>$params['openid'], 'is_delete_time'=>0];
|
||||
$user = $m->where($where)->find();
|
||||
if(!empty($user))
|
||||
{
|
||||
$data = $user;
|
||||
}
|
||||
|
||||
// 返回成功
|
||||
$this->ajaxReturn('授权成功', 0, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* [ClientCenter 用户中心]
|
||||
* @author Devil
|
||||
|
|
@ -243,5 +248,25 @@ class UserController extends CommonController
|
|||
// 返回数据
|
||||
$this->ajaxReturn(L('common_operation_success'), 0, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度小程序获取用户信息
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-11-06
|
||||
* @desc description
|
||||
*/
|
||||
public function GetBaiduUserInfo()
|
||||
{
|
||||
$_POST['config'] = C('baidu_mini_program_config');
|
||||
$result = (new \Library\BaiduAuth())->GetAuthUserInfo($_POST);
|
||||
if($result['status'] == 0)
|
||||
{
|
||||
$this->AuthUserProgram($result['data'], 'baidu_openid');
|
||||
} else {
|
||||
$this->ajaxReturn($result['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -124,9 +124,6 @@ return array(
|
|||
|
||||
// 开启U带域名
|
||||
'url_domain_deploy' => true,
|
||||
|
||||
// 支付宝appid
|
||||
'alipay_mini_appid' => '2018071160553916',
|
||||
|
||||
// 支付业务类型,支付插件根据业务类型自动生成支付入口文件
|
||||
'payment_business_type_all' => [
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class Alipay
|
|||
private function SoonPayApp($data, $config)
|
||||
{
|
||||
$parameter = array(
|
||||
'app_id' => C('alipay_mini_appid'),
|
||||
'app_id' => MyC('common_app_mini_alipay_appid'),
|
||||
'method' => 'alipay.trade.app.pay',
|
||||
'format' => 'JSON',
|
||||
'charset' => 'utf-8',
|
||||
|
|
@ -445,21 +445,6 @@ class Alipay
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [SyncRsaVerify 同步返回签名验证]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2017-09-25T13:13:39+0800
|
||||
* @param [array] $data [返回数据]
|
||||
* @param [boolean] $key [数据key]
|
||||
*/
|
||||
private function SyncRsaVerify($data, $key)
|
||||
{
|
||||
$string = json_encode($data[$key], JSON_UNESCAPED_UNICODE);
|
||||
return $this->AlipayRsaVerify($string, $data['sign']);
|
||||
}
|
||||
|
||||
/**
|
||||
* [MyRsaSign 签名字符串]
|
||||
* @author Devil
|
||||
|
|
@ -471,32 +456,10 @@ class Alipay
|
|||
*/
|
||||
private function MyRsaSign($prestr)
|
||||
{
|
||||
$public_key = file_get_contents(ROOT_PATH.'Rsakeys/rsa_mini_private_key_pkcs8.pem');
|
||||
$pkeyid = openssl_pkey_get_private($public_key);
|
||||
return openssl_sign($prestr, $sign, $pkeyid, OPENSSL_ALGO_SHA256) ? base64_encode($sign) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* [AlipayRsaVerify 支付宝验证签名]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2017-09-24T08:39:50+0800
|
||||
* @param [string] $prestr [需要签名的字符串]
|
||||
* @param [string] $sign [签名结果]
|
||||
* @return [boolean] [正确true, 错误false]
|
||||
*/
|
||||
private function AlipayRsaVerify($prestr, $sign)
|
||||
{
|
||||
$sign = base64_decode($sign);
|
||||
$public_key = file_get_contents(ROOT_PATH.'Rsakeys/rsa_alipay_mini_public_key.pem');
|
||||
$pkeyid = openssl_pkey_get_public($public_key);
|
||||
if($pkeyid)
|
||||
{
|
||||
$verify = openssl_verify($prestr, $sign, $pkeyid, OPENSSL_ALGO_SHA256);
|
||||
openssl_free_key($pkeyid);
|
||||
}
|
||||
return (isset($verify) && $verify == 1) ? true : false;
|
||||
$res = "-----BEGIN RSA PRIVATE KEY-----\n";
|
||||
$res .= wordwrap(MyC('common_app_mini_alipay_rsa_private'), 64, "\n", true);
|
||||
$res .= "\n-----END RSA PRIVATE KEY-----";
|
||||
return openssl_sign($prestr, $sign, $res, OPENSSL_ALGO_SHA256) ? base64_encode($sign) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -510,8 +473,10 @@ class Alipay
|
|||
*/
|
||||
private function MyRsaDecrypt($content)
|
||||
{
|
||||
$priKey = file_get_contents(ROOT_PATH.'Rsakeys/mini_private_key.pem');
|
||||
$res = openssl_get_privatekey($priKey);
|
||||
$res = "-----BEGIN PUBLIC KEY-----\n";
|
||||
$res .= wordwrap(MyC('common_app_mini_alipay_rsa_public'), 64, "\n", true);
|
||||
$res .= "\n-----END PUBLIC KEY-----";
|
||||
$res = openssl_get_privatekey($res);
|
||||
$content = base64_decode($content);
|
||||
$result = '';
|
||||
for($i=0; $i<strlen($content)/128; $i++)
|
||||
|
|
@ -524,6 +489,46 @@ class Alipay
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* [OutRsaVerify 支付宝验证签名]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2017-09-24T08:39:50+0800
|
||||
* @param [string] $prestr [需要签名的字符串]
|
||||
* @param [string] $sign [签名结果]
|
||||
* @return [boolean] [正确true, 错误false]
|
||||
*/
|
||||
private function OutRsaVerify($prestr, $sign)
|
||||
{
|
||||
$res = "-----BEGIN PUBLIC KEY-----\n";
|
||||
$res .= wordwrap(MyC('common_app_mini_alipay_out_rsa_public'), 64, "\n", true);
|
||||
$res .= "\n-----END PUBLIC KEY-----";
|
||||
$pkeyid = openssl_pkey_get_public($res);
|
||||
$sign = base64_decode($sign);
|
||||
if($pkeyid)
|
||||
{
|
||||
$verify = openssl_verify($prestr, $sign, $pkeyid, OPENSSL_ALGO_SHA256);
|
||||
openssl_free_key($pkeyid);
|
||||
}
|
||||
return (isset($verify) && $verify == 1) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [SyncRsaVerify 同步返回签名验证]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2017-09-25T13:13:39+0800
|
||||
* @param [array] $data [返回数据]
|
||||
* @param [boolean] $key [数据key]
|
||||
*/
|
||||
private function SyncRsaVerify($data, $key)
|
||||
{
|
||||
$string = json_encode($data[$key], JSON_UNESCAPED_UNICODE);
|
||||
return $this->OutRsaVerify($string, $data['sign']);
|
||||
}
|
||||
|
||||
/**
|
||||
* [HttpRequest 网络请求]
|
||||
* @author Devil
|
||||
|
|
@ -582,7 +587,7 @@ class Alipay
|
|||
{
|
||||
// 请求参数
|
||||
$params = [
|
||||
'app_id' => C('alipay_mini_appid'),
|
||||
'app_id' => MyC('common_app_mini_alipay_appid'),
|
||||
'method' => 'alipay.open.app.qrcode.create',
|
||||
'charset' => 'utf-8',
|
||||
'format' => 'JSON',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Library;
|
||||
|
||||
/**
|
||||
* 百度用户授权驱动
|
||||
* @author Devil
|
||||
* @version V_1.0.0
|
||||
*/
|
||||
class BaiduAuth
|
||||
{
|
||||
/**
|
||||
* [__construct 构造方法]
|
||||
*/
|
||||
public function __construct(){}
|
||||
|
||||
/**
|
||||
* 用户授权
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-11-06
|
||||
* @desc description
|
||||
* @param [array] $params [输入参数]
|
||||
*/
|
||||
public function GetAuthUserInfo($params = [])
|
||||
{
|
||||
if(empty($params['authcode']))
|
||||
{
|
||||
return ['status'=>-1, 'msg'=>'授权码有误'];
|
||||
}
|
||||
if(empty($params['config']))
|
||||
{
|
||||
return ['status'=>-1, 'msg'=>'配置有误'];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'code' => $params['authcode'],
|
||||
'client_id' => $params['config']['key'],
|
||||
'sk' => $params['config']['secret'],
|
||||
];
|
||||
$result = $this->HttpRequest('https://openapi.baidu.com/nalogin/getSessionKeyByCode', $data);
|
||||
if(empty($result['openid']))
|
||||
{
|
||||
return ['status'=>-1, 'msg'=>$result['error_description']];
|
||||
}
|
||||
return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result];
|
||||
}
|
||||
|
||||
/**
|
||||
* [HttpRequest 网络请求]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2017-09-25T09:10:46+0800
|
||||
* @param [string] $url [请求url]
|
||||
* @param [array] $data [发送数据]
|
||||
* @return [mixed] [请求返回数据]
|
||||
*/
|
||||
private function HttpRequest($url, $data)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
$body_string = '';
|
||||
if(is_array($data) && 0 < count($data))
|
||||
{
|
||||
foreach($data as $k => $v)
|
||||
{
|
||||
$body_string .= $k.'='.urlencode($v).'&';
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body_string);
|
||||
}
|
||||
$headers = array('content-type: application/x-www-form-urlencoded;charset=UTF-8');
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
$reponse = curl_exec($ch);
|
||||
if(curl_errno($ch))
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if(200 !== $httpStatusCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
curl_close($ch);
|
||||
return json_decode($reponse, true);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue