Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞鱼0526
ShopXO
提交
ac9b2812
ShopXO
项目概览
飞鱼0526
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac9b2812
编写于
10月 27, 2019
作者:
D
Devil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
头条小程序用户绑定
上级
13e79871
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
174 addition
and
55 deletion
+174
-55
application/api/controller/User.php
application/api/controller/User.php
+71
-0
application/service/UserService.php
application/service/UserService.php
+2
-1
extend/base/ToutiaoAuth.php
extend/base/ToutiaoAuth.php
+55
-0
public/appmini/old/toutiao/app.js
public/appmini/old/toutiao/app.js
+43
-50
public/appmini/old/toutiao/pages/login/login.js
public/appmini/old/toutiao/pages/login/login.js
+3
-4
未找到文件。
application/api/controller/User.php
浏览文件 @
ac9b2812
...
...
@@ -248,6 +248,77 @@ class User extends Common
return
DataReturn
(
$result
[
'msg'
],
-
10
);
}
/**
* 头条小程序用户授权
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-10-27
* @desc description
*/
public
function
ToutiaoUserAuth
()
{
$this
->
data_post
[
'config'
]
=
[
'appid'
=>
MyC
(
'common_app_mini_toutiao_appid'
,
'tt65341389fa1e87f3'
),
'secret'
=>
MyC
(
'common_app_mini_toutiao_appsecret'
,
'9ea496422c189390d2d3ec8eec597fbcf3e1e5a7'
),
];
$result
=
(
new
\
base\ToutiaoAuth
())
->
GetAuthCode
(
$this
->
data_post
);
if
(
$result
[
'status'
]
==
0
)
{
return
DataReturn
(
'授权登录成功'
,
0
,
$result
[
'data'
][
'openid'
]);
}
return
DataReturn
(
$result
[
'msg'
],
-
10
);
}
/**
* 头条小程序获取用户信息
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-10-27
* @desc description
*/
public
function
ToutiaoUserInfo
()
{
// 参数校验
$p
=
[
[
'checked_type'
=>
'empty'
,
'key_name'
=>
'openid'
,
'error_msg'
=>
'openid为空'
,
],
[
'checked_type'
=>
'empty'
,
'key_name'
=>
'userinfo'
,
'error_msg'
=>
'用户信息为空'
,
],
];
$ret
=
ParamsChecked
(
$this
->
data_post
,
$p
);
if
(
$ret
!==
true
)
{
return
DataReturn
(
$ret
,
-
1
);
}
// 先从数据库获取用户信息
$user
=
UserService
::
AppUserInfoHandle
(
null
,
'toutiao_openid'
,
$this
->
data_post
[
'openid'
]);
if
(
empty
(
$user
))
{
$result
=
json_decode
(
htmlspecialchars_decode
(
$this
->
data_post
[
'userinfo'
]),
true
);
if
(
is_array
(
$result
))
{
$result
[
'nick_name'
]
=
isset
(
$result
[
'nickName'
])
?
$result
[
'nickName'
]
:
''
;
$result
[
'avatar'
]
=
isset
(
$result
[
'avatarUrl'
])
?
$result
[
'avatarUrl'
]
:
''
;
$result
[
'gender'
]
=
empty
(
$result
[
'gender'
])
?
0
:
(
$result
[
'gender'
]
==
2
)
?
1
:
2
;
$result
[
'openid'
]
=
$this
->
data_post
[
'openid'
];
$result
[
'referrer'
]
=
isset
(
$this
->
data_post
[
'referrer'
])
?
$this
->
data_post
[
'referrer'
]
:
0
;
return
UserService
::
AuthUserProgram
(
$result
,
'toutiao_openid'
);
}
}
else
{
return
DataReturn
(
'授权成功'
,
0
,
$user
);
}
return
DataReturn
(
empty
(
$result
)
?
'获取用户信息失败'
:
$result
,
-
100
);
}
/**
* [ClientCenter 用户中心]
* @author Devil
...
...
application/service/UserService.php
浏览文件 @
ac9b2812
...
...
@@ -315,6 +315,7 @@ class UserService
'status'
=>
intval
(
$params
[
'status'
]),
'alipay_openid'
=>
isset
(
$params
[
'alipay_openid'
])
?
$params
[
'alipay_openid'
]
:
''
,
'baidu_openid'
=>
isset
(
$params
[
'baidu_openid'
])
?
$params
[
'baidu_openid'
]
:
''
,
'toutiao_openid'
=>
isset
(
$params
[
'toutiao_openid'
])
?
$params
[
'toutiao_openid'
]
:
''
,
'weixin_openid'
=>
isset
(
$params
[
'weixin_openid'
])
?
$params
[
'weixin_openid'
]
:
''
,
'weixin_unionid'
=>
isset
(
$params
[
'weixin_unionid'
])
?
$params
[
'weixin_unionid'
]
:
''
,
'weixin_web_openid'
=>
isset
(
$params
[
'weixin_web_openid'
])
?
$params
[
'weixin_web_openid'
]
:
''
,
...
...
@@ -1696,7 +1697,7 @@ class UserService
public
static
function
AppUserInfoHandle
(
$user_id
=
null
,
$where_field
=
null
,
$where_value
=
null
,
$user
=
[])
{
// 获取用户信息
$field
=
'id,username,nickname,mobile,email,avatar,alipay_openid,weixin_openid,weixin_unionid,weixin_web_openid,baidu_openid,integral,locking_integral'
;
$field
=
'id,username,nickname,mobile,email,avatar,alipay_openid,weixin_openid,weixin_unionid,weixin_web_openid,baidu_openid,
toutiao_openid,
integral,locking_integral'
;
if
(
!
empty
(
$user_id
))
{
$user
=
self
::
UserInfo
(
'id'
,
$user_id
,
$field
);
...
...
extend/base/ToutiaoAuth.php
0 → 100644
浏览文件 @
ac9b2812
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace
base
;
/**
* 头条用户授权驱动
* @author Devil
* @version V_1.0.0
*/
class
ToutiaoAuth
{
/**
* [__construct 构造方法]
*/
public
function
__construct
(){}
/**
* 用户授权
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-10-27
* @desc description
* @param [array] $params [输入参数]
*/
public
function
GetAuthCode
(
$params
=
[])
{
if
(
empty
(
$params
[
'authcode'
]))
{
return
[
'status'
=>-
1
,
'msg'
=>
'授权码有误'
];
}
if
(
empty
(
$params
[
'config'
]))
{
return
[
'status'
=>-
1
,
'msg'
=>
'配置有误'
];
}
// 获取授权
$url
=
'https://developer.toutiao.com/api/apps/jscode2session?appid='
.
$params
[
'config'
][
'appid'
]
.
'&secret='
.
$params
[
'config'
][
'secret'
]
.
'&code='
.
$params
[
'authcode'
];
$result
=
json_decode
(
file_get_contents
(
$url
),
true
);
if
(
empty
(
$result
[
'openid'
]))
{
return
[
'status'
=>-
1
,
'msg'
=>
$result
[
'errmsg'
]];
}
return
[
'status'
=>
0
,
'msg'
=>
'授权成功'
,
'data'
=>
$result
];
}
}
?>
\ No newline at end of file
public/appmini/old/toutiao/app.js
浏览文件 @
ac9b2812
...
...
@@ -67,7 +67,7 @@ App({
// 请求地址
request_url
:
"
{{request_url}}
"
,
request_url
:
'
http://tp5-dev.com/
'
,
request_url
:
'
https://test.shopxo.net/
'
,
//
request_url: 'https://test.shopxo.net/',
// 基础信息
application_title
:
"
{{application_title}}
"
,
...
...
@@ -145,7 +145,7 @@ App({
return
(
this
.
data
.
request_url
+
"
index.php?s=/
"
+
m
+
"
/
"
+
c
+
"
/
"
+
a
+
"
&application=app&application_client_type=
weixin
"
+
"
&application=app&application_client_type=
toutiao
"
+
"
&token=
"
+
token
+
"
&ajax=ajax
"
+
...
...
@@ -235,62 +235,55 @@ App({
* object 回调操作对象
* method 回调操作对象的函数
* openid 用户openid
* auth_data 授权数据
*/
get_user_login_info
(
object
,
method
,
openid
,
auth_data
)
{
console
.
log
(
'
user-info
'
)
;
get_user_login_info
(
object
,
method
,
openid
)
{
var
self
=
this
;
tt
.
getUserInfo
({
success
(
res
)
{
console
.
log
(
`getUserInfo调用成功
${
res
.
userInfo
}
`
);
// 邀请人参数
var
params
=
tt
.
getStorageSync
(
self
.
data
.
cache_launch_info_key
)
||
null
;
var
referrer
=
(
params
==
null
)
?
0
:
(
params
.
referrer
||
0
);
// 远程处理用户数据
tt
.
request
({
url
:
self
.
get_request_url
(
'
toutiaouserinfo
'
,
'
user
'
),
method
:
'
POST
'
,
data
:
{
"
userinfo
"
:
res
.
rawData
,
"
openid
"
:
openid
,
"
referrer
"
:
referrer
},
dataType
:
'
json
'
,
header
:
{
'
content-type
'
:
'
application/x-www-form-urlencoded
'
},
success
:
(
res
)
=>
{
tt
.
hideLoading
();
if
(
res
.
data
.
code
==
0
)
{
tt
.
setStorage
({
key
:
self
.
data
.
cache_user_info_key
,
data
:
res
.
data
.
data
,
success
:
(
res
)
=>
{
if
(
typeof
object
===
'
object
'
&&
(
method
||
null
)
!=
null
)
{
object
[
method
]();
}
},
fail
:
()
=>
{
self
.
showToast
(
'
用户信息缓存失败
'
);
}
});
}
else
{
self
.
showToast
(
res
.
data
.
msg
);
}
},
fail
:
()
=>
{
tt
.
hideLoading
();
self
.
showToast
(
'
服务器请求出错
'
);
},
});
},
fail
(
res
)
{
app
.
showToast
(
"
获取用户授权信息失败
"
);
}
});
return
false
;
// 邀请人参数
var
params
=
tt
.
getStorageSync
(
this
.
data
.
cache_launch_info_key
)
||
null
;
var
referrer
=
(
params
==
null
)
?
0
:
(
params
.
referrer
||
0
);
// 远程解密数据
var
self
=
this
;
tt
.
request
({
url
:
self
.
get_request_url
(
'
wechatuserinfo
'
,
'
user
'
),
method
:
'
POST
'
,
data
:
{
"
encrypted_data
"
:
auth_data
.
encryptedData
,
"
iv
"
:
auth_data
.
iv
,
"
openid
"
:
openid
,
"
referrer
"
:
referrer
},
dataType
:
'
json
'
,
header
:
{
'
content-type
'
:
'
application/x-www-form-urlencoded
'
},
success
:
(
res
)
=>
{
tt
.
hideLoading
();
if
(
res
.
data
.
code
==
0
)
{
tt
.
setStorage
({
key
:
self
.
data
.
cache_user_info_key
,
data
:
res
.
data
.
data
,
success
:
(
res
)
=>
{
if
(
typeof
object
===
'
object
'
&&
(
method
||
null
)
!=
null
)
{
object
[
method
]();
}
},
fail
:
()
=>
{
self
.
showToast
(
'
用户信息缓存失败
'
);
}
});
}
else
{
self
.
showToast
(
res
.
data
.
msg
);
}
},
fail
:
()
=>
{
tt
.
hideLoading
();
self
.
showToast
(
'
服务器请求出错
'
);
},
});
},
/**
...
...
public/appmini/old/toutiao/pages/login/login.js
浏览文件 @
ac9b2812
...
...
@@ -139,16 +139,15 @@ Page({
var
validation
=
[
{
fields
:
'
mobile
'
,
msg
:
'
请填写手机号码
'
},
{
fields
:
'
verify
'
,
msg
:
'
请填写验证码
'
},
{
fields
:
'
weixin
_openid
'
,
msg
:
'
授权id不能为空
'
}
{
fields
:
'
toutiao
_openid
'
,
msg
:
'
授权id不能为空
'
}
];
e
.
detail
.
value
[
'
weixin_openid
'
]
=
this
.
data
.
user
.
weixin
_openid
;
e
.
detail
.
value
[
'
toutiao_openid
'
]
=
this
.
data
.
user
.
toutiao
_openid
;
e
.
detail
.
value
[
'
nickname
'
]
=
this
.
data
.
user
.
nickname
;
e
.
detail
.
value
[
'
avatar
'
]
=
this
.
data
.
user
.
avatar
;
e
.
detail
.
value
[
'
province
'
]
=
this
.
data
.
user
.
province
;
e
.
detail
.
value
[
'
city
'
]
=
this
.
data
.
user
.
city
;
e
.
detail
.
value
[
'
gender
'
]
=
this
.
data
.
user
.
gender
;
e
.
detail
.
value
[
'
weixin_unionid
'
]
=
this
.
data
.
user
.
weixin_unionid
||
''
;
e
.
detail
.
value
[
'
app_type
'
]
=
'
weixin
'
;
e
.
detail
.
value
[
'
app_type
'
]
=
'
toutiao
'
;
e
.
detail
.
value
[
'
referrer
'
]
=
(
params
==
null
)
?
(
this
.
data
.
user
.
referrer
||
0
)
:
(
params
.
referrer
||
0
);
if
(
app
.
fields_check
(
e
.
detail
.
value
,
validation
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录