Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
b7575e93
Commit
b7575e93
authored
Sep 19, 2019
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add course lbs
parent
6c28df54
Pipeline
#13924
passed with stage
in 11 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
6 deletions
+121
-6
test.js
app/controller/common/test.js
+13
-0
common.js
app/router/common.js
+1
-0
lbs.js
app/service/course/lbs.js
+98
-0
config.local.js
config/config.local.js
+9
-6
No files found.
app/controller/common/test.js
0 → 100644
View file @
b7575e93
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
TestController
extends
Controller
{
async
test
()
{
const
{
service
,
ctx
}
=
this
;
const
from
=
{
lng
:
120.069206
,
lat
:
30.291121
};
const
to
=
{
lng
:
120.212997
,
lat
:
30.29133
};
const
ret
=
await
service
.
course
.
lbs
.
getLBSDistance
(
'driving'
,
from
,
[
to
]);
ctx
.
success
(
ret
);
}
}
module
.
exports
=
TestController
;
app/router/common.js
View file @
b7575e93
...
@@ -4,4 +4,5 @@ module.exports = app => {
...
@@ -4,4 +4,5 @@ module.exports = app => {
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/common'
);
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/common'
);
router
.
get
(
'third_oss_signature'
,
'/oss/signature'
,
'common.oss.signature'
);
// 业务的 oss 签名
router
.
get
(
'third_oss_signature'
,
'/oss/signature'
,
'common.oss.signature'
);
// 业务的 oss 签名
router
.
get
(
'third_test'
,
'/test'
,
'common.test.test'
);
};
};
app/service/course/lbs.js
0 → 100644
View file @
b7575e93
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
class
LbsService
extends
Service
{
// 计算两个经纬度之间的距离,用Haversine公式,单位:m
async
getDistance
(
from
,
to
)
{
const
rad_from
=
from
.
lat
*
Math
.
PI
/
180.0
;
const
rad_to
=
to
.
lat
*
Math
.
PI
/
180.0
;
const
sub_lat
=
rad_from
-
rad_to
;
const
sub_lng
=
from
.
lng
*
Math
.
PI
/
180.0
-
to
.
lng
*
Math
.
PI
/
180.0
;
const
r
=
6378137
;
// 地球半径
const
distance
=
r
*
2
*
Math
.
asin
(
Math
.
sqrt
(
Math
.
pow
(
Math
.
sin
(
sub_lat
/
2
),
2
)
+
Math
.
cos
(
rad_from
)
*
Math
.
cos
(
rad_to
)
*
Math
.
pow
(
Math
.
sin
(
sub_lng
/
2
),
2
)));
return
distance
;
}
// 腾讯位置服务WebService API,距离计算(一对多)
// 返回示例:
// {
// "results": [
// {
// "from": {
// "lat": 39.983171,
// "lng": 116.308479
// },
// "to": {
// "lat": 39.996059,
// "lng": 116.353454
// },
// "distance": 5354.7,
// "duration": 1678
// },
// {
// "from": {
// "lat": 39.983171,
// "lng": 116.308479
// },
// "to": {
// "lat": 39.949226,
// "lng": 116.394309
// },
// "distance": 10495.8, // 起点到终点的距离,单位:米。如果radius半径过小或者无法搜索到,则返回-1
// "duration": 2635 // 表示从起点到终点的结合路况的时间,秒为单位。 注:步行方式不计算耗时,该值始终为0
// }
// ]
// }
async
getLBSDistance
(
mode
=
'driving'
,
from
,
toArr
)
{
const
{
ctx
}
=
this
;
const
to
=
[];
let
result
=
[];
for
(
const
v
of
toArr
)
{
to
.
push
(
String
(
v
.
lat
)
+
','
+
String
(
v
.
lng
));
}
const
params
=
{
mode
,
// driving, walking;默认driving
from
:
String
(
from
.
lat
)
+
','
+
String
(
from
.
lng
),
to
:
to
.
join
(
';'
),
key
:
ctx
.
app
.
config
.
TX_LBS_KEY
,
};
const
resp
=
await
ctx
.
helper
.
send_request
(
ctx
.
app
.
config
.
TX_LBS_DISTANCE_URL
,
params
,
{
method
:
'GET'
});
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx
.
logger
.
info
(
'tx_lbs_distance_params: '
+
JSON
.
stringify
(
params
));
ctx
.
logger
.
info
(
'tx_lbs_distance_resp: '
+
JSON
.
stringify
(
resp
));
if
(
resp
.
status
===
200
)
{
// 判断响应是否正确
if
(
resp
.
data
.
status
===
0
)
{
result
=
resp
.
data
.
result
.
elements
;
}
}
return
{
results
:
result
};
}
// 地址解析
async
getLBSAddress
(
address
)
{
const
{
ctx
}
=
this
;
let
result
=
{};
const
params
=
{
address
,
key
:
ctx
.
app
.
config
.
TX_LBS_KEY
,
};
const
resp
=
await
ctx
.
helper
.
send_request
(
ctx
.
app
.
config
.
TX_LBS_ADDRESS_URL
,
params
,
{
method
:
'GET'
});
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx
.
logger
.
info
(
'tx_lbs_address_resp: '
+
JSON
.
stringify
(
resp
));
if
(
resp
.
status
===
200
)
{
// 判断响应是否正确
if
(
resp
.
data
.
status
===
0
)
{
result
=
resp
.
data
.
result
;
}
}
return
{
result
};
}
}
module
.
exports
=
LbsService
;
config/config.local.js
View file @
b7575e93
...
@@ -133,17 +133,20 @@ module.exports = appInfo => {
...
@@ -133,17 +133,20 @@ module.exports = appInfo => {
config
.
OUT_P_NODE_URL
=
'https://dev-nginx.jianbing.com'
;
config
.
OUT_P_NODE_URL
=
'https://dev-nginx.jianbing.com'
;
//数盒魔方
//
数盒魔方
config
.
SHUHEMOFANG_APP_KEY
=
'BdNFbog6'
;
config
.
SHUHEMOFANG_APP_KEY
=
'BdNFbog6'
;
config
.
SHUHEMOFANG_APP_SECRET
=
'a695e9b3c0f1e3f15fb0b958fd3a4b67'
;
config
.
SHUHEMOFANG_APP_SECRET
=
'a695e9b3c0f1e3f15fb0b958fd3a4b67'
;
config
.
SHUHEMOFANG_URL
=
'https://api.soohaid.com:8211/api/mobile/factor3s'
;
config
.
SHUHEMOFANG_URL
=
'https://api.soohaid.com:8211/api/mobile/factor3s'
;
//微信支付相关内容
// 微信支付相关内容
config
.
MCH_APPID
=
'wx0369cb31f505d8ce'
;
//商户关联的APPID
config
.
MCH_APPID
=
'wx0369cb31f505d8ce'
;
// 商户关联的APPID
config
.
MCH_ID
=
'1516742591'
;
//商户id
config
.
MCH_ID
=
'1516742591'
;
// 商户id
config
.
MCH_KEY
=
'xiXigu4008635151jianbing6floor12'
;
//商户秘钥
config
.
MCH_KEY
=
'xiXigu4008635151jianbing6floor12'
;
// 商户秘钥
// 腾讯位置服务
config
.
TX_LBS_KEY
=
'TNHBZ-A7C36-5DISQ-EM2JH-332V5-PGFW5'
;
config
.
TX_LBS_DISTANCE_URL
=
'https://apis.map.qq.com/ws/distance/v1/'
;
// 距离计算(一对多)
config
.
TX_LBS_ADDRESS_URL
=
'https://apis.map.qq.com/ws/geocoder/v1/'
;
// 地址解析;逆地址解析
return
config
;
return
config
;
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment