Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
qianhe-slsy
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xuwenhao
qianhe-slsy
Commits
a0685375
Commit
a0685375
authored
Mar 07, 2024
by
yuanchao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
20240307微信支付,站点就近匹配
parent
d1fffc15
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
535 additions
and
1 deletions
+535
-1
qianhe-admin/pom.xml
+12
-0
qianhe-admin/src/main/java/com/qianhe/system/controller/WaterStationController.java
+10
-0
qianhe-admin/src/main/java/com/qianhe/system/controller/WeChatPayController.java
+67
-0
qianhe-admin/src/main/java/com/qianhe/system/domain/WeChatPay.java
+69
-0
qianhe-admin/src/main/java/com/qianhe/system/service/IWaterStationService.java
+9
-0
qianhe-admin/src/main/java/com/qianhe/system/service/impl/WaterStationServiceImpl.java
+27
-0
qianhe-admin/src/main/java/com/qianhe/system/service/impl/WaterUserAddressServiceImpl.java
+6
-1
qianhe-admin/src/main/java/com/qianhe/system/service/impl/WeChatPayService.java
+109
-0
qianhe-admin/src/main/java/com/qianhe/system/utils/AMapUtils.java
+73
-0
qianhe-admin/src/main/java/com/qianhe/system/utils/WeChatPayUrl.java
+25
-0
qianhe-admin/src/main/java/com/qianhe/system/utils/WxChatPayCommonUtil.java
+128
-0
No files found.
qianhe-admin/pom.xml
View file @
a0685375
...
@@ -61,6 +61,13 @@
...
@@ -61,6 +61,13 @@
<artifactId>
qianhe-generator
</artifactId>
<artifactId>
qianhe-generator
</artifactId>
</dependency>
</dependency>
<!-- 微信支付 SDK -->
<dependency>
<groupId>
com.github.wxpay
</groupId>
<artifactId>
wxpay-sdk
</artifactId>
<version>
0.0.3
</version>
</dependency>
<!-- hutool -->
<!-- hutool -->
<dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<groupId>
cn.hutool
</groupId>
...
@@ -114,6 +121,11 @@
...
@@ -114,6 +121,11 @@
<version>
0.2.12
</version>
<version>
0.2.12
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.18.24
</version>
</dependency>
</dependencies>
</dependencies>
...
...
qianhe-admin/src/main/java/com/qianhe/system/controller/WaterStationController.java
View file @
a0685375
...
@@ -156,4 +156,14 @@ public class WaterStationController extends BaseController
...
@@ -156,4 +156,14 @@ public class WaterStationController extends BaseController
WaterStationVo
recentlyStation
=
waterStationService
.
getRecentlyStation
(
lon
,
lat
);
WaterStationVo
recentlyStation
=
waterStationService
.
getRecentlyStation
(
lon
,
lat
);
return
success
(
recentlyStation
);
return
success
(
recentlyStation
);
}
}
/**
* 订单页获取最近站点信息
*/
@GetMapping
(
"/getRecentlyStation1"
)
public
AjaxResult
getRecentlyStation1
(
@RequestParam
(
"address"
)
String
address
,
@RequestParam
(
"address1"
)
String
address1
){
WaterStationVo
recentlyStation
=
waterStationService
.
getRecentlyStation1
(
address
,
address1
);
return
success
(
recentlyStation
);
}
}
}
qianhe-admin/src/main/java/com/qianhe/system/controller/WeChatPayController.java
0 → 100644
View file @
a0685375
package
com
.
qianhe
.
system
.
controller
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.github.wxpay.sdk.WXPayUtil
;
import
com.qianhe.common.core.domain.AjaxResult
;
import
com.qianhe.system.domain.WaterGoodsCart
;
import
com.qianhe.system.domain.WeChatPay
;
import
com.qianhe.system.service.impl.WeChatPayService
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
com
.
qianhe
.
common
.
core
.
domain
.
AjaxResult
.
success
;
/**
* @author yc
* @version 1.0
* @className WeChatPayController
* @date 2024/3/4 15:26
* @description 支付下单
*/
@RestController
@RequestMapping
(
"/weChatPay"
)
public
class
WeChatPayController
{
@Value
(
"${wx.appId}"
)
private
String
appId
;
@Value
(
"${wx.mchId}"
)
private
String
mchId
;
@Value
(
"${wx.apiKey}"
)
private
String
apiKey
;
@GetMapping
(
"/pay"
)
public
AjaxResult
orderPay
(
@RequestBody
WaterGoodsCart
goods
){
Map
<
String
,
Object
>
ResultMap
=
new
HashMap
<
String
,
Object
>();
try
{
WeChatPay
weChatPay
=
new
WeChatPay
();
weChatPay
.
setAppid
(
appId
);
//公众号appid
weChatPay
.
setMch_id
(
mchId
);
weChatPay
.
setApi_key
(
apiKey
);
//api密钥
weChatPay
.
setNonce_str
(
WXPayUtil
.
generateNonceStr
());
// 32位随机字符串
weChatPay
.
setBody
(
goods
.
getGoodsName
()+
goods
.
getGoodsTypeName
()+
goods
.
getGoodsId
());
// 商品描述
weChatPay
.
setTotal_fee
(
String
.
valueOf
(
goods
.
getGoodsPrice
()));
//标价金额
weChatPay
.
setOut_trade_no
(
IdUtil
.
simpleUUID
());
// 商户订单号 唯一
weChatPay
.
setNotify_url
(
"https://notify_url"
);
//异步回调地址
weChatPay
.
setTrade_type
(
"JSAPI"
);
// 交易类型 JSAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
weChatPay
.
setAttach
(
"附加数据NO.1"
);
//附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
ResultMap
=
WeChatPayService
.
Unifiedorder
(
weChatPay
);
//log.info("返回结果:{}",JSONUtil.toJsonStr(ResultMap));
}
catch
(
Exception
e
)
{
ResultMap
.
put
(
"code"
,
2
);
ResultMap
.
put
(
"msg"
,
"系统异常错误代码:"
+
e
.
getMessage
());
e
.
printStackTrace
();
}
return
success
(
JSONUtil
.
toJsonStr
(
ResultMap
));
}
}
\ No newline at end of file
qianhe-admin/src/main/java/com/qianhe/system/domain/WeChatPay.java
0 → 100644
View file @
a0685375
package
com
.
qianhe
.
system
.
domain
;
import
lombok.Data
;
/**
* @author yc
* @version 1.0
* @className WeChatPay
* @date 2024/3/4 13:42
* @description 微信支付预下单实体类
*/
@Data
public
class
WeChatPay
{
//返回状态码 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断
public
String
return_code
;
//返回信息 当return_code为FAIL时返回信息为错误原因 ,例如 签名失败 参数格式校验错误
private
String
return_msg
;
//公众账号ID 调用接口提交的公众账号ID
private
String
appid
;
//商户号 调用接口提交的商户号
private
String
mch_id
;
//api密钥 详见:https://pay.weixin.qq.com/index.php/extend/employee
private
String
api_key
;
//设备号 自定义参数,可以为请求支付的终端设备号等
private
String
device_info
;
//随机字符串 5K8264ILTKCH16CQ2502SI8ZNMTM67VS 微信返回的随机字符串
private
String
nonce_str
;
//签名 微信返回的签名值,详见签名算法:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=4_3
private
String
sign
;
//业务结果 SUCCESS SUCCESS/FAIL
private
String
result_code
;
//错误代码 当result_code为FAIL时返回错误代码,详细参见下文错误列表
private
String
err_code
;
//错误代码描述 当result_code为FAIL时返回错误描述,详细参见下文错误列表
private
String
err_code_des
;
//交易类型 JSAPI JSAPI -JSAPI支付 NATIVE -Native支付 APP -APP支付 说明详见;https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=4_2
private
String
trade_type
;
//预支付交易会话标识 微信生成的预支付会话标识,用于后续接口调用中使用,该值有效期为2小时
private
String
prepay_id
;
//二维码链接 weixin://wxpay/bizpayurl/up?pr=NwY5Mz9&groupid=00 trade_type=NATIVE时有返回,此url用于生成支付二维码,然后提供给用户进行扫码支付。注意:code_url的值并非固定,使用时按照URL格式转成二维码即可
private
String
code_url
;
//商品描述 商品简单描述,该字段请按照规范传递,具体请见 https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=4_2
private
String
body
;
//商家订单号 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|* 且在同一个商户号下唯一。详见商户订单号 https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=4_2
private
String
out_trade_no
;
//标价金额 订单总金额,单位为分,详见支付金额 https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=4_2
private
String
total_fee
;
//终端IP 支持IPV4和IPV6两种格式的IP地址。用户的客户端IP
private
String
spbill_create_ip
;
//通知地址 异步接收微信支付结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。公网域名必须为https,如果是走专线接入,使用专线NAT IP或者私有回调域名可使用http
private
String
notify_url
;
//子商户号 sub_mch_id 非必填(商户不需要传入,服务商模式才需要传入) 微信支付分配的子商户号
private
String
sub_mch_id
;
//附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
private
String
attach
;
//商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
private
String
out_refund_no
;
//退款总金额,单位为分,只能为整数,可部分退款。详见支付金额 https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=4_2
private
String
refund_fee
;
//退款原因 若商户传入,会在下发给用户的退款消息中体现退款原因 注意:若订单退款金额≤1元,且属于部分退款,则不会在退款消息中体现退款原因
private
String
refund_desc
;
//交易结束时间 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则 注意:最短失效时间间隔必须大于5分钟
private
String
time_expire
;
//用户标识 trade_type=JSAPI,此参数必传,用户在主商户appid下的唯一标识。openid和sub_openid可以选传其中之一,如果选择传sub_openid,则必须传sub_appid。下单前需要调用【网页授权获取用户信息: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html 】接口获取到用户的Openid。
private
String
openid
;
}
\ No newline at end of file
qianhe-admin/src/main/java/com/qianhe/system/service/IWaterStationService.java
View file @
a0685375
...
@@ -84,6 +84,15 @@ public interface IWaterStationService
...
@@ -84,6 +84,15 @@ public interface IWaterStationService
*/
*/
WaterStationVo
getRecentlyStation
(
double
lon
,
double
lat
);
WaterStationVo
getRecentlyStation
(
double
lon
,
double
lat
);
/**
* 下单页查询最新站点
* @param lon
* @param lat
* @return
*/
WaterStationVo
getRecentlyStation1
(
String
address
,
String
address1
);
/**
/**
* 查询站点下拉框(PC端)
* 查询站点下拉框(PC端)
* @return
* @return
...
...
qianhe-admin/src/main/java/com/qianhe/system/service/impl/WaterStationServiceImpl.java
View file @
a0685375
...
@@ -8,6 +8,7 @@ import com.qianhe.system.domain.WaterStationUser;
...
@@ -8,6 +8,7 @@ import com.qianhe.system.domain.WaterStationUser;
import
com.qianhe.system.mapper.WaterStationMapper
;
import
com.qianhe.system.mapper.WaterStationMapper
;
import
com.qianhe.system.mapper.WaterStationUserMapper
;
import
com.qianhe.system.mapper.WaterStationUserMapper
;
import
com.qianhe.system.service.IWaterStationService
;
import
com.qianhe.system.service.IWaterStationService
;
import
com.qianhe.system.utils.AMapUtils
;
import
com.qianhe.system.utils.PositionUtil
;
import
com.qianhe.system.utils.PositionUtil
;
import
com.qianhe.system.vo.WaterStationUserVo
;
import
com.qianhe.system.vo.WaterStationUserVo
;
import
com.qianhe.system.vo.WaterStationVo
;
import
com.qianhe.system.vo.WaterStationVo
;
...
@@ -249,6 +250,32 @@ public class WaterStationServiceImpl implements IWaterStationService
...
@@ -249,6 +250,32 @@ public class WaterStationServiceImpl implements IWaterStationService
return
collect
.
get
(
0
);
return
collect
.
get
(
0
);
}
}
@Override
public
WaterStationVo
getRecentlyStation1
(
String
address
,
String
address1
)
{
double
[]
doubles
=
AMapUtils
.
addressToGPS
(
address
);
double
lon
=
doubles
[
0
];
double
lat
=
doubles
[
1
];
//查询所有站点信息
List
<
WaterStation
>
waterStations
=
waterStationMapper
.
selectWaterStationList
(
new
WaterStation
());
List
<
WaterStationVo
>
waterStationVoList
=
new
ArrayList
<>();
//循环站点,计算符合距离的站点
for
(
WaterStation
waterStation
:
waterStations
)
{
//判断用户和站点之前的距离是否在站点管辖范围之内
boolean
inCircle
=
PositionUtil
.
isInCircle
(
lon
,
lat
,
waterStation
.
getStationLonTen
(),
waterStation
.
getStationLatTen
(),
"5000"
);
//计算距离
double
distance
=
PositionUtil
.
getDistance
(
lon
,
lat
,
waterStation
.
getStationLonTen
(),
waterStation
.
getStationLatTen
(),
Ellipsoid
.
WGS84
);
if
(
inCircle
){
WaterStationVo
waterStationVo
=
new
WaterStationVo
();
BeanUtils
.
copyProperties
(
waterStation
,
waterStationVo
);
waterStationVo
.
setDistance
(
distance
);
waterStationVoList
.
add
(
waterStationVo
);
}
}
//根据距离排序,选出最近的站点
List
<
WaterStationVo
>
collect
=
waterStationVoList
.
stream
().
sorted
(
Comparator
.
comparing
(
WaterStationVo:
:
getDistance
)).
collect
(
Collectors
.
toList
());
return
collect
.
get
(
0
);
}
/**
/**
* 查询站点下拉框(PC端)
* 查询站点下拉框(PC端)
* @return
* @return
...
...
qianhe-admin/src/main/java/com/qianhe/system/service/impl/WaterUserAddressServiceImpl.java
View file @
a0685375
...
@@ -77,7 +77,12 @@ public class WaterUserAddressServiceImpl extends ServiceImpl<WaterUserAddressMap
...
@@ -77,7 +77,12 @@ public class WaterUserAddressServiceImpl extends ServiceImpl<WaterUserAddressMap
//将该用户所有默认地址设备不默认
//将该用户所有默认地址设备不默认
waterUserAddressMapper
.
updateDefaultAddress
(
waterUserAddress
.
getWaterUserId
());
waterUserAddressMapper
.
updateDefaultAddress
(
waterUserAddress
.
getWaterUserId
());
}
}
return
waterUserAddressMapper
.
updateWaterUserAddress
(
waterUserAddress
);
try
{
waterUserAddressMapper
.
updateWaterUserAddress
(
waterUserAddress
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
1
;
}
}
/**
/**
...
...
qianhe-admin/src/main/java/com/qianhe/system/service/impl/WeChatPayService.java
0 → 100644
View file @
a0685375
package
com
.
qianhe
.
system
.
service
.
impl
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.github.wxpay.sdk.WXPayConstants
;
import
com.github.wxpay.sdk.WXPayUtil
;
import
com.qianhe.system.domain.WeChatPay
;
import
com.qianhe.system.utils.WeChatPayUrl
;
import
com.qianhe.system.utils.WxChatPayCommonUtil
;
import
java.text.DecimalFormat
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
/**
* @author yc
* @version 1.0
* @className WeChatPayService
* @date 2024/3/4 13:45
* @description 微信支付接口封装服务
*/
public
class
WeChatPayService
{
private
static
final
DecimalFormat
df
=
new
DecimalFormat
(
"#"
);
/**
* 微信支付统一预下单接口 请查看接口规则 https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_1
* @param weChatPay 参数值appid 商户id等等
* @return Map<String, Object> NATIVE支付则返回二维码扫描地址
* @throws Exception
*/
public
static
Map
<
String
,
Object
>
Unifiedorder
(
WeChatPay
weChatPay
)
throws
Exception
{
Map
<
String
,
Object
>
ResultMap
=
new
HashMap
<
String
,
Object
>();
//todo 创建请求参数
SortedMap
<
String
,
String
>
req
=
new
TreeMap
<
String
,
String
>();
req
.
put
(
"appid"
,
weChatPay
.
getAppid
());
//公众号
req
.
put
(
"mch_id"
,
weChatPay
.
getMch_id
());
// 商户号
req
.
put
(
"nonce_str"
,
WXPayUtil
.
generateNonceStr
());
// 32位随机字符串
req
.
put
(
"body"
,
weChatPay
.
getBody
());
// 商品描述
req
.
put
(
"out_trade_no"
,
weChatPay
.
getOut_trade_no
());
// 商户订单号
req
.
put
(
"total_fee"
,
df
.
format
(
Double
.
parseDouble
(
weChatPay
.
getTotal_fee
())
*
100
));
// 标价金额(分)
req
.
put
(
"spbill_create_ip"
,
weChatPay
.
getSpbill_create_ip
());
// 终端IP
req
.
put
(
"notify_url"
,
weChatPay
.
getNotify_url
());
// 回调地址
req
.
put
(
"trade_type"
,
weChatPay
.
getTrade_type
());
// 交易类型
req
.
put
(
"attach"
,
weChatPay
.
getAttach
());
// 签名
if
(
ObjectUtil
.
isNotEmpty
(
weChatPay
.
getSub_mch_id
()))
{
//todo 服务商模式
req
.
put
(
"sub_mch_id"
,
weChatPay
.
getSub_mch_id
());
//子商户号 微信支付 分配的子商户号
}
if
(
ObjectUtil
.
isNotEmpty
(
weChatPay
.
getTime_expire
()))
{
//todo 设置订单结束时间
//交易结束时间 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。
req
.
put
(
"time_expire"
,
weChatPay
.
getTime_expire
());
}
if
(
ObjectUtil
.
isNotEmpty
(
weChatPay
.
getOpenid
()))
{
//todo JSAPI支付
req
.
put
(
"openid"
,
weChatPay
.
getOpenid
());
//用户标识 trade_type=JSAPI,此参数必传,用户在主商户appid下的唯一标识。openid和sub_openid可以选传其中之一,如果选择传sub_openid,则必须传sub_appid。下单前需要调用【网页授权获取用户信息: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html 】接口获取到用户的Openid。
}
req
.
put
(
"sign"
,
WXPayUtil
.
generateSignature
(
req
,
weChatPay
.
getApi_key
(),
WXPayConstants
.
SignType
.
MD5
));
// 签名
//todo 生成要发送的 xml
String
xmlBody
=
WXPayUtil
.
generateSignedXml
(
req
,
weChatPay
.
getApi_key
());
System
.
err
.
println
(
String
.
format
(
"微信支付预下单请求 xml 格式:\n%s"
,
xmlBody
));
//todo 发送 POST 请求 统一下单 API 并携带 xmlBody 内容,然后获得返回接口结果
String
result
=
WxChatPayCommonUtil
.
httpsRequest
(
WeChatPayUrl
.
Uifiedorder
,
"POST"
,
xmlBody
);
System
.
err
.
println
(
String
.
format
(
"%s"
,
result
));
//todo 将返回结果从 xml 格式转换为 map 格式
Map
<
String
,
String
>
WxResultMap
=
WXPayUtil
.
xmlToMap
(
result
);
//todo 判断通信状态 此字段是通信标识,非交易标识
if
(
ObjectUtil
.
isNotEmpty
(
WxResultMap
.
get
(
"return_code"
))
&&
WxResultMap
.
get
(
"return_code"
).
equals
(
"SUCCESS"
))
{
//todo 业务结果
if
(
WxResultMap
.
get
(
"result_code"
).
equals
(
"SUCCESS"
))
{
//todo 预下单成功
ResultMap
.
put
(
"code"
,
0
);
ResultMap
.
put
(
"msg"
,
"预下单成功"
);
//微信订单号
ResultMap
.
put
(
"out_trade_no"
,
weChatPay
.
getOut_trade_no
());
switch
(
WxResultMap
.
get
(
"trade_type"
))
{
case
"NATIVE"
:
//二维码地址
ResultMap
.
put
(
"QrCode"
,
WxResultMap
.
get
(
"code_url"
));
break
;
case
"MWEB"
:
//二维码地址
ResultMap
.
put
(
"mweb_url"
,
WxResultMap
.
get
(
"mweb_url"
));
break
;
case
"JSAPI"
:
//预支付交易会话标识 微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时
ResultMap
.
put
(
"prepay_id"
,
WxResultMap
.
get
(
"prepay_id"
));
break
;
}
}
else
{
//todo 下单失败
ResultMap
.
put
(
"code"
,
2
);
ResultMap
.
put
(
"msg"
,
WxResultMap
.
get
(
"err_code_des"
));
}
}
else
{
//todo 通信异常
ResultMap
.
put
(
"code"
,
2
);
ResultMap
.
put
(
"msg"
,
WxResultMap
.
get
(
"return_msg"
));
//当return_code为FAIL时返回信息为错误原因 ,例如 签名失败 参数格式校验错误
}
return
ResultMap
;
}
}
\ No newline at end of file
qianhe-admin/src/main/java/com/qianhe/system/utils/AMapUtils.java
0 → 100644
View file @
a0685375
package
com
.
qianhe
.
system
.
utils
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @author yc
* @version 1.0
* @className AMapUtils
* @date 2024/3/7 10:19
* @description 根据位置计算经纬度
*/
public
class
AMapUtils
{
// 高德地图key
public
static
final
String
KEY
=
"6dc239658cd94e2007b4f3c933106693"
;
private
static
Pattern
pattern
=
Pattern
.
compile
(
"\"location\":\"(\\d+\\.\\d+),(\\d+\\.\\d+)\""
);
/**
* 通过具体位置,获取对应地图上的坐标: 经度、纬度
*
* @param address
* @return
*/
public
static
double
[]
addressToGPS
(
String
address
)
{
try
{
String
url
=
String
.
format
(
"http://restapi.amap.com/v3/geocode/geo?&s=rsv3&address=%s&key=%s"
,
address
,
KEY
);
URL
myURL
=
null
;
URLConnection
httpsConn
=
null
;
try
{
myURL
=
new
URL
(
url
);
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
InputStreamReader
insr
=
null
;
BufferedReader
br
=
null
;
httpsConn
=
(
URLConnection
)
myURL
.
openConnection
();
// 不使用代理
if
(
httpsConn
!=
null
)
{
insr
=
new
InputStreamReader
(
httpsConn
.
getInputStream
(),
"UTF-8"
);
br
=
new
BufferedReader
(
insr
);
String
data
=
""
;
String
line
=
null
;
while
((
line
=
br
.
readLine
())!=
null
){
data
+=
line
;
}
Matcher
matcher
=
pattern
.
matcher
(
data
);
if
(
matcher
.
find
()
&&
matcher
.
groupCount
()
==
2
)
{
double
[]
gps
=
new
double
[
2
];
gps
[
0
]
=
Double
.
valueOf
(
matcher
.
group
(
1
));
gps
[
1
]
=
Double
.
valueOf
(
matcher
.
group
(
2
));
return
gps
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
null
;
}
public
static
void
main
(
String
[]
args
)
{
String
address
=
"广州市总统大酒店"
;
double
[]
doubles
=
addressToGPS
(
address
);
System
.
out
.
println
(
address
+
"、经度: "
+
doubles
[
0
]);
System
.
out
.
println
(
address
+
"、纬度: "
+
doubles
[
1
]);
}
}
\ No newline at end of file
qianhe-admin/src/main/java/com/qianhe/system/utils/WeChatPayUrl.java
0 → 100644
View file @
a0685375
package
com
.
qianhe
.
system
.
utils
;
/**
* @author yc
* @version 1.0
* @className WeChatPayUrl
* @date 2024/3/4 10:17
* @description 微信支付接口Url列表
*/
public
class
WeChatPayUrl
{
//统一下单预下单接口url
public
static
final
String
Uifiedorder
=
"https://api.mch.weixin.qq.com/pay/unifiedorder"
;
//订单状态查询接口URL
public
static
final
String
Orderquery
=
"https://api.mch.weixin.qq.com/pay/orderquery"
;
//订单申请退款
public
static
final
String
Refund
=
"https://api.mch.weixin.qq.com/secapi/pay/refund"
;
//付款码 支付
public
static
final
String
MicroPay
=
"https://api.mch.weixin.qq.com/pay/micropay"
;
//微信网页授权 获取“code”请求地址
public
static
final
String
GainCodeUrl
=
"https://open.weixin.qq.com/connect/oauth2/authorize"
;
//微信网页授权 获取“code” 回调地址
public
static
final
String
GainCodeRedirect_uri
=
"http://i5jmxe.natappfree.cc/boss/WeChatPayMobile/SkipPage.html"
;
}
\ No newline at end of file
qianhe-admin/src/main/java/com/qianhe/system/utils/WxChatPayCommonUtil.java
0 → 100644
View file @
a0685375
package
com
.
qianhe
.
system
.
utils
;
import
com.qianhe.common.utils.StringUtils
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.*
;
import
java.net.URL
;
/**
* @author yc
* @version 1.0
* @className WxChatPayCommonUtil
* @date 2024/3/4 10:17
* @description 自定义微信支付工具类
*/
public
class
WxChatPayCommonUtil
{
/**
* 发送 http 请求
* @param requestUrl 请求路径
* @param requestMethod 请求方式(GET/POST/PUT/DELETE/...)
* @param outputStr 请求参数体
* @return 结果信息
*/
public
static
String
httpsRequest
(
String
requestUrl
,
String
requestMethod
,
String
outputStr
)
{
try
{
URL
url
=
new
URL
(
requestUrl
);
HttpsURLConnection
conn
=
(
HttpsURLConnection
)
url
.
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
false
);
// 设置请求方式(GET/POST)
conn
.
setRequestMethod
(
requestMethod
);
conn
.
setRequestProperty
(
"content-type"
,
"application/x-www-form-urlencoded"
);
// 当outputStr不为null时向输出流写数据
if
(
null
!=
outputStr
)
{
OutputStream
outputStream
=
conn
.
getOutputStream
();
// 注意编码格式
outputStream
.
write
(
outputStr
.
getBytes
(
"UTF-8"
));
outputStream
.
close
();
}
// 从输入流读取返回内容
InputStream
inputStream
=
conn
.
getInputStream
();
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"utf-8"
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
str
=
null
;
StringBuffer
buffer
=
new
StringBuffer
();
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
// 释放资源
bufferedReader
.
close
();
inputStreamReader
.
close
();
inputStream
.
close
();
inputStream
=
null
;
conn
.
disconnect
();
return
buffer
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 获取ip
* @param request 请求
* @return ip 地址
*/
public
static
String
getIp
(
HttpServletRequest
request
)
{
if
(
request
==
null
)
{
return
""
;
}
String
ip
=
request
.
getHeader
(
"X-Requested-For"
);
if
(
StringUtils
.
isEmpty
(
ip
)
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
}
if
(
StringUtils
.
isEmpty
(
ip
)
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
StringUtils
.
isEmpty
(
ip
)
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
StringUtils
.
isEmpty
(
ip
)
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
}
if
(
StringUtils
.
isEmpty
(
ip
)
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
}
if
(
StringUtils
.
isEmpty
(
ip
)
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getRemoteAddr
();
}
return
ip
;
}
/**
* 从流中读取微信返回的xml数据
* @param httpServletRequest
* @return
* @throws IOException
*/
public
static
String
readXmlFromStream
(
HttpServletRequest
httpServletRequest
)
throws
IOException
,
IOException
{
InputStream
inputStream
=
httpServletRequest
.
getInputStream
();
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
));
final
StringBuffer
sb
=
new
StringBuffer
();
String
line
=
null
;
try
{
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
);
}
}
finally
{
bufferedReader
.
close
();
inputStream
.
close
();
}
return
sb
.
toString
();
}
/**
* 设置返回给微信服务器的xml信息
* @param returnCode
* @param returnMsg
* @return
*/
public
static
String
setReturnXml
(
String
returnCode
,
String
returnMsg
)
{
return
"<xml><return_code><![CDATA["
+
returnCode
+
"]]></return_code><return_msg><![CDATA["
+
returnMsg
+
"]]></return_msg></xml>"
;
}
}
\ No newline at end of file
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