Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ijianbo
rest Api To Miniprogram
提交
fb1bf6e8
rest Api To Miniprogram
项目概览
ijianbo
/
rest Api To Miniprogram
通知
22
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
rest Api To Miniprogram
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fb1bf6e8
编写于
3月 20, 2021
作者:
ijianbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1、修复编辑分类页无法打开媒体库的bug
2、调整登录程序
上级
28438a05
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
116 addition
and
1 deletion
+116
-1
includes/api/ram-rest-weixin-controller.php
includes/api/ram-rest-weixin-controller.php
+109
-0
includes/filter/ram-custom-category.php
includes/filter/ram-custom-category.php
+7
-1
未找到文件。
includes/api/ram-rest-weixin-controller.php
浏览文件 @
fb1bf6e8
...
...
@@ -133,6 +133,27 @@ class RAM_REST_Weixin_Controller extends WP_REST_Controller{
'schema'
=>
array
(
$this
,
'get_public_item_schema'
),
)
);
register_rest_route
(
$this
->
namespace
,
'/'
.
$this
->
resource_name
.
'/userlogin'
,
array
(
array
(
'methods'
=>
'POST'
,
'callback'
=>
array
(
$this
,
'userlogin'
),
'permission_callback'
=>
array
(
$this
,
'get_openid_permissions_check'
),
'args'
=>
array
(
'context'
=>
$this
->
get_context_param
(
array
(
'default'
=>
'view'
)
),
'avatarUrl'
=>
array
(
'required'
=>
true
),
'nickname'
=>
array
(
'required'
=>
true
),
'js_code'
=>
array
(
'required'
=>
true
)
)
),
'schema'
=>
array
(
$this
,
'get_public_item_schema'
),
)
);
}
function
updateUserInfo
(
$request
)
...
...
@@ -291,6 +312,94 @@ class RAM_REST_Weixin_Controller extends WP_REST_Controller{
}
}
function
userlogin
(
$request
)
{
$js_code
=
$request
[
'js_code'
];
// $encryptedData=$request['encryptedData'];
// $iv=$request['iv'];
$avatarUrl
=
$request
[
'avatarUrl'
];
$nickname
=
empty
(
$request
[
'nickname'
])
?
''
:
$request
[
'nickname'
];
$appid
=
get_option
(
'wf_appid'
);
$appsecret
=
get_option
(
'wf_secret'
);
if
(
empty
(
$appid
)
||
empty
(
$appsecret
)
){
return
new
WP_Error
(
'error'
,
'appid或appsecret为空'
,
array
(
'status'
=>
500
)
);
}
else
{
$access_url
=
"https://api.weixin.qq.com/sns/jscode2session?appid="
.
$appid
.
"&secret="
.
$appsecret
.
"&js_code="
.
$js_code
.
"&grant_type=authorization_code"
;
$access_result
=
https_request
(
$access_url
);
if
(
$access_result
==
'ERROR'
)
{
return
new
WP_Error
(
'error'
,
'API错误:'
.
json_encode
(
$access_result
),
array
(
'status'
=>
501
)
);
}
$api_result
=
json_decode
(
$access_result
,
true
);
if
(
empty
(
$api_result
[
'openid'
]
)
||
empty
(
$api_result
[
'session_key'
]
))
{
return
new
WP_Error
(
'error'
,
'API错误:'
.
json_encode
(
$api_result
),
array
(
'status'
=>
502
)
);
}
$openId
=
$api_result
[
'openid'
];
$sessionKey
=
$api_result
[
'session_key'
];
$userId
=
0
;
$nickname
=
filterEmoji
(
$nickname
);
$_nickname
=
base64_encode
(
$nickname
);
$_nickname
=
strlen
(
$_nickname
)
>
49
?
substr
(
$_nickname
,
49
)
:
$_nickname
;
// $avatarUrl= $data['avatarUrl'];
if
(
!
username_exists
(
$openId
)
)
{
$new_user_data
=
apply_filters
(
'new_user_data'
,
array
(
'user_login'
=>
$openId
,
'first_name'
=>
$nickname
,
'nickname'
=>
$nickname
,
'user_nicename'
=>
$_nickname
,
'display_name'
=>
$nickname
,
'user_pass'
=>
null
,
'user_email'
=>
$openId
.
'@weixin.com'
)
);
$userId
=
wp_insert_user
(
$new_user_data
);
if
(
is_wp_error
(
$userId
)
||
empty
(
$userId
)
||
$userId
==
0
)
{
return
new
WP_Error
(
'error'
,
'插入wordpress用户错误:'
,
array
(
'status'
=>
500
)
);
}
update_user_meta
(
$userId
,
'avatar'
,
$avatarUrl
);
update_user_meta
(
$userId
,
'usertype'
,
"weixin"
);
}
else
{
$user
=
get_user_by
(
'login'
,
$openId
);
$userId
=
$user
->
ID
;
$userdata
=
array
(
'ID'
=>
$user
->
ID
,
'first_name'
=>
$nickname
,
'nickname'
=>
$nickname
,
'user_nicename'
=>
$_nickname
,
'display_name'
=>
$nickname
,
'user_email'
=>
$openId
.
'@weixin.com'
);
$userId
=
wp_update_user
(
$userdata
);
if
(
is_wp_error
(
$userId
)){
return
new
WP_Error
(
'error'
,
'更新wp用户错误:'
,
array
(
'status'
=>
500
)
);
}
if
(
delete_user_meta
(
$userId
,
'avatar'
)
)
{
update_user_meta
(
$userId
,
'avatar'
,
$avatarUrl
);
}
if
(
delete_user_meta
(
$userId
,
'usertype'
)
)
{
$flag
=
update_user_meta
(
$userId
,
'usertype'
,
"weixin"
);
}
}
$userLevel
=
getUserLevel
(
$userId
);
$result
[
"code"
]
=
"success"
;
$result
[
"message"
]
=
"获取用户信息成功"
;
$result
[
"status"
]
=
"200"
;
$result
[
"openid"
]
=
$openId
;
$result
[
"userLevel"
]
=
$userLevel
;
$result
[
"userId"
]
=
$userId
;
$response
=
rest_ensure_response
(
$result
);
return
$response
;
}
}
function
sendmessage
(
$request
)
{
$openid
=
$request
[
'openid'
];
...
...
includes/filter/ram-custom-category.php
浏览文件 @
fb1bf6e8
<?php
function
custom_fields_rest_prepare_category
(
$data
,
$item
,
$request
)
{
function
custom_fields_rest_prepare_category
(
$data
,
$item
,
$request
)
{
$category_thumbnail_image
=
''
;
$temp
=
''
;
$openid
=
$request
[
"openid"
];
...
...
@@ -87,6 +90,9 @@ add_action( 'category_edit_form_fields', 'weixin_edit_term_catcover_field' );
function
weixin_edit_term_catcover_field
(
$term
)
{
$default
=
''
;
$catcover
=
get_term_meta
(
$term
->
term_id
,
'catcover'
,
true
);
if
(
function_exists
(
'wp_enqueue_media'
)
)
{
wp_enqueue_media
();
}
wp_enqueue_script
(
'rawscript'
,
plugins_url
()
.
'/'
.
REST_API_TO_MINIPROGRAM_PLUGIN_NAME
.
'/includes/js/script.js'
,
false
,
'1.0'
);
if
(
!
$catcover
)
$catcover
=
$default
;
?>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录