Commit 36d84cb5 by jscat

nyx: oss文件上传

desc: 第一版本的文件上传成功
func:
1. 文件上传至阿里云oss
2. 回调函数返回应用服务器
todo
1. 设计tag的格式
2. 从nyxkey应用服务器写数据到database
parent c8663bd4
//app.js
//app.js
......@@ -39,6 +39,16 @@ App({
socketClose: false,
socketOpen: false,
//文件上传数据格式
postData : {
photoArray: [],
photoTag: [],
photoTitle: "",
photoContent: "",
photoCategory: "",
},
},
onLaunch: function () {
......
{
{
......@@ -13,7 +13,10 @@
"pages/my/rank/rank",
"pages/my/user/user",
"pages/my/myposts/myposts",
"pages/logs/logs"
"pages/logs/logs",
"pages/post/post",
"pages/post/edit/edit",
"pages/post/submit/submit"
],
"window": {
"backgroundTextStyle": "light",
......@@ -40,6 +43,12 @@
"selectedIconPath": "./icon/discover2.png"
},
{
"pagePath": "pages/post/post",
"text": "添加",
"iconPath": "./icon/add.png",
"selectedIconPath": "./icon/add.png"
},
{
"pagePath": "pages/key/key",
"text": "知识",
"iconPath": "./icon/key.png",
......
//config.js API全局域名配置
//config.js API全局域名配置
//config.js API全局域名配置
var prod = 0;
var local = 1;
var test = 0;
var local = 0;
var test = 1;
var debug = 0; //是否打印调试信息
var host_key = "https://fun.hisuhong.com";
......@@ -52,5 +52,7 @@ var config={
city_query_url: host_key + "/api/nyx/city/query",
member_query_url: host_key + "/api/nyx/member/pos/query",
socket_url: socket_url,
oss_token_url: host_key + "/api/nyx/oss/getToken",
oss_callback_url: login_url + "/api/nyx/oss/callback",
}
module.exports=config;
\ No newline at end of file
// pages/key/key.js
// pages/key/key.js
......@@ -322,9 +322,9 @@ Page({
//分享(带参数),在onLoad接收参数
onShareAppMessage: function () {
return {
title: 'xx小程序',
path: 'pages/index/index?id=123&name="zansan"&age=23', // 路径,传递参数到指定页面。
imageUrl: '../../imgs/avater.jpg' //自定义分享封面
title: '让有趣被发现',
path: 'pages/key/key', // 路径,传递参数到指定页面。
imageUrl: '../../icon/images/nyx.png' //自定义分享封面
}
},
/**
......@@ -551,6 +551,37 @@ const getData = (url, param) => {
})
}
//通过Promise方式进行敏感内容监测
const messageCheck = (url, param) => {
return new Promise((resolve, reject) => {
/* start+of_wx.request */
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=your app id&secret=your secret',
method: 'GET',
success: res => {
var access_token = res.data.access_token;
wx.request({
method: 'POST',
url: 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='+access_token,
data: {
content: param
},
success(res) {
if (res.errcode !== 87014) {
// 合格
}
}
})
},
fail() {
console.log(res);
}
})
/* end_of_wx.request */
})
}
//表情文件
function emotionFun() {
let emoArr = [
......
{
{
{
"usingComponents": {
"type-cmp": "/components/type/type"
},
"usingComponents": {},
"navigationBarTitleText": "让有趣被发现 - 酒肆"
}
\ No newline at end of file
package cn.com.fun.nyxkey.api.service.impl;
package cn.com.fun.nyxkey.api.service.impl;
......@@ -112,6 +112,12 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
public JSONResult Rockwell_ossServiceGetToken(String userName, String tokenName)
{
/*
1. accessKeyId
2. accessKeySecret
3. securityToken
4. expiration
*/
Map<String, String> map = getSTSRoleAccessKeyId(userName, tokenName);
return getToken(map);
}
......@@ -124,6 +130,8 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
String accessId = map.get("accessKeyId");
//String accessKey = aliyunOssAccessKeySecret; // 请填写您的AccessKeySecret。
String accessKey = map.get("accessKeySecret");
String securityToken = map.get("securityToken");
String endpoint = aliyunOssEndpoint; // 请填写您的 endpoint。
String bucket = aliyunOssBucket; // 请填写您的 bucketname 。
String host = "http://" + bucket + "." + endpoint; // host的格式为 bucketname.endpoint
......@@ -134,7 +142,7 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
OSSClient client = new OSSClient(endpoint, accessId, accessKey);
Map<String, String> respMap = new LinkedHashMap<String, String>();
try {
long expireTime = 30;
long expireTime = 60;
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
Date expiration = new Date(expireEndTime);
PolicyConditions policyConds = new PolicyConditions();
......@@ -147,6 +155,7 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
String postSignature = client.calculatePostSignature(postPolicy);
respMap.put("accessid", accessId);
respMap.put("securityToken", securityToken);
respMap.put("policy", encodedPolicy);
respMap.put("signature", postSignature);
respMap.put("dir", dir);
......@@ -154,13 +163,14 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
respMap.put("expire", String.valueOf(expireEndTime / 1000));
// respMap.put("expire", formatISO8601Date(expiration));
JSONObject jasonCallback = new JSONObject();
jasonCallback.put("callbackUrl", callbackUrl);
jasonCallback.put("callbackBody",
"filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}");
jasonCallback.put("callbackBodyType", "application/x-www-form-urlencoded");
String base64CallbackBody = BinaryUtil.toBase64String(jasonCallback.toString().getBytes());
respMap.put("callback", base64CallbackBody);
// 小程序里指定
// JSONObject jasonCallback = new JSONObject();
// jasonCallback.put("callbackUrl", callbackUrl);
// jasonCallback.put("callbackBody",
// "filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}");
// jasonCallback.put("callbackBodyType", "application/x-www-form-urlencoded");
// String base64CallbackBody = BinaryUtil.toBase64String(jasonCallback.toString().getBytes());
// respMap.put("callback", base64CallbackBody);
} catch (Exception e) {
// Assert.fail(e.getMessage());
......@@ -172,12 +182,9 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
return json;
}
//step1: 获取STS临时授权的token
//step1: 获取STS临时授securityToken权的token
public Map<String, String> getSTSRoleAccessKeyId(String userName, String tokenName)
{
// if (StringUtils.isBlank(userName) || StringUtils.isBlank(tokenName)) {
// return new JSONResult(ExceptionMsg.OSSTokenNameIsBlack);
// }
Map<String,String> map = new HashMap<String,String>();
try {
......
package cn.com.fun.nyxkey.api.web.controller;
package cn.com.fun.nyxkey.api.web.controller;
......@@ -5,6 +5,7 @@ import cn.com.fun.nyxkey.api.service.*;
import cn.com.fun.nyxkey.api.web.common.ResponseHelper;
import cn.com.fun.nyxkey.api.web.common.ResponseWrapper;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -47,5 +48,29 @@ public class OssApiController {
return ossService.Rockwell_ossServiceGetToken(userName, tokenName);
}
// refer:
// https://blog.csdn.net/feiyst/article/details/88431621
// SpringBoot 出现 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
// 前端请求传Json对象则后端使用@RequestParam
// 前端请求传Json对象的字符串则后端使用@RequestBody。
@RequestMapping(value = "/nyx/oss/callback", method = RequestMethod.POST)
@ResponseBody
public JSONObject callback(
@RequestParam(value = "filename", required = false, defaultValue = "0") String filename,
@RequestParam(value = "size", required = false, defaultValue = "0") String size,
@RequestParam(value = "height", required = false, defaultValue = "0") String height,
@RequestParam(value = "width", required = false, defaultValue = "0") String width,
@RequestParam(value = "tag", required = false, defaultValue = "0") String tag,
@RequestParam(value = "title", required = false, defaultValue = "0") String title,
@RequestParam(value = "content", required = false, defaultValue = "0") String content,
@RequestParam(value = "category", required = false, defaultValue = "0") String category
){
System.out.println("===callback_\n");
System.out.println("===filename: "+filename+"&tag="+tag+"&title="+title+"&content="+content+"&category="+category);
JSONObject result = new JSONObject();
result.put("Status","OK");
return result;
}
}
server:
server:
......@@ -67,14 +67,14 @@ weixin:
aliyun:
oss:
REGION_CN_HANGZHOU: cn-hangzhou
REGION_CN_HANGZHOU: cn-shanghai
AccessKeyID: LTAI4GA88LJ82UtfMUrozDp3
AccessKeySecret: OWyAIN3OTobk9MuKvZ7DMnr5cJxNND
STS_API_VERSION: 2015-04-01
RoleArn: acs:ram::1956317109339291:role/nyxtokengeneratorrolepolicy
PolicyFile: policy/bucket_full_access_policy.txt
TokenExpireTime: 30
endpoint: oss-cn-hangzhou.aliyuncs.com
endpoint: oss-cn-shanghai.aliyuncs.com
bucket: 930-test-sh
callbackUrl: http://88.88.88.88:8888
dir: user-dir/
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论