Skip to content

Commit

Permalink
add upmppay
Browse files Browse the repository at this point in the history
  • Loading branch information
dzh committed Nov 26, 2015
1 parent 7f4d572 commit 69003a6
Show file tree
Hide file tree
Showing 60 changed files with 2,763 additions and 345 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ dzh_11@qq.com (personal)
* Plugin Feature
* scala plugin
* clojure plugin
* auto plugin class in plugin.properties
* New Plugin
* jframe-monitor jframe runtime information
* upgrade plugin from Jframev1
Expand Down
Binary file modified jframe-pay/doc/mysql/jframe_pay.mwb
Binary file not shown.
Binary file modified jframe-pay/doc/mysql/jframe_pay.mwb.bak
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
*/
public class OrderUpmp extends OrderBase {
/**
* 支付支持的卡类型,'{cardType=01}'-借记卡,'{cardType=02}'-信用卡,不填都支持
* TODO 支付支持的卡类型,'{cardType=01}'-借记卡,'{cardType=02}'-信用卡,不填都支持
*/
public String merReserved;

public String version;

public String traceNo;

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@
<result property="openid" column="openid" />
</resultMap>

<resultMap id="orderUpmpResultMap" type="OrderUpmp">
<id property="payNo" column="pay_no" />
<result property="account" column="account" />
<result property="backUrl" column="back_url" />
<result property="orderCreateTime" column="order_create_time"
typeHandler="jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler" />
<result property="orderFinishTime" column="order_finish_time"
typeHandler="jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler" />
<result property="orderNo" column="order_no" />
<result property="payStatus" column="pay_status" />
<result property="payAmount" column="pay_amount" />
<result property="payCurrency" column="pay_currency" />
<result property="payDesc" column="pay_desc" />
<result property="payGroup" column="pay_group" />
<result property="payTimeout" column="pay_timeout"
typeHandler="jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler" />
<result property="merReserved" column="mer_reserved" />
<result property="version" column="version" />
<result property="traceNo" column="trace_no" />
</resultMap>

<resultMap id="orderDetailResultMap" type="OrderDetail">
<id property="id" column="id" />
<result property="accountFrom" column="account_from" />
Expand All @@ -86,6 +107,82 @@
<result property="transType" column="trans_type" />
</resultMap>

<select id="selectOrderUpmp" parameterType="string" resultMap="orderUpmpResultMap">
select * from order_upmp where pay_no = #{payNo}
</select>

<select id="selectOrderUpmpWithOrderNo" parameterType="string"
resultMap="orderUpmpResultMap">
select * from order_upmp where order_no = #{orderNo}
</select>

<insert id="insertOrderUpmp" parameterType="OrderUpmp">
insert into
order_upmp
(
<if test="account != null">account,</if>
<if test="backUrl != null">back_url,</if>
order_create_time,
<if test="orderFinishTime != null">order_finish_time,</if>
order_no,
pay_status,
pay_amount,
<if test="payCurrency != null">pay_currency,</if>
<if test="payDesc != null">pay_desc,</if>
<if test="payGroup != null">pay_group,</if>
pay_no,
<if test="payTimeout != null">pay_timeout,</if>
<if test="transType != null">trans_type,</if>
<if test="merReserved != null">mer_reserved,</if>
<if test="version != null">version,</if>
<if test="traceNo != null">trace_no,</if>
create_time)
values
(
<if test="account != null">#{account},</if>
<if test="backUrl != null">#{backUrl},</if>
now(),
<if test="orderFinishTime != null">#{orderFinishTime,typeHandler=jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler},
</if>
#{orderNo},
#{payStatus},
#{payAmount},
<if test="payCurrency != null">#{payCurrency},</if>
<if test="payDesc != null">#{payDesc},</if>
<if test="payGroup != null">#{payGroup},</if>
#{payNo},
<if test="payTimeout != null">#{payTimeout,typeHandler=jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler},
</if>
<if test="transType != null">#{transType},</if>
<if test="merReserved != null">#{merReserved},</if>
<if test="version != null">#{version},</if>
<if test="traceNo != null">#{traceNo},</if>
now())
</insert>

<update id="updateOrderUpmp" parameterType="OrderUpmp">
update `order_upmp`
<set>
<if test="account != null">account=#{account},</if>
<if test="backUrl != null">back_url=#{backUrl},</if>
<if test="orderFinishTime != null">order_finish_time=#{orderFinishTime,typeHandler=jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler},
</if>
<if test="orderNo != null">order_no=#{orderNo},</if>
<if test="payAmount != null">pay_amount=#{payAmount},</if>
<if test="payCurrency != null">pay_currency=#{payCurrency},</if>
<if test="payDesc != null">pay_desc=#{payDesc},</if>
<if test="payGroup != null">pay_group=#{payGroup},</if>
<if test="payStatus != null">pay_status=#{payStatus},</if>
<if test="payTimeout != null">pay_timeout=#{payTimeout,typeHandler=jframe.pay.domain.dao.mapper.SqlTimestampTypeHandler},
</if>
<if test="transType != null">trans_type=#{transType},</if>
<if test="merReserved != null">mer_reserved=#{merReserved},</if>
<if test="version != null">version=#{version},</if>
<if test="traceNo != null">trace_no=#{traceNo},</if>
</set>
where pay_no = #{payNo}
</update>

<insert id="insertOrderWx" parameterType="OrderWx">
insert into order_wx
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum ReqOp {
/************************** Order **********************************/
CONSUME("consume", "consume"), QRYOD("qryod", "query order"), ALIBACK(
"aliback", "alipay back"), WXBACK("wxback", "wxpay back"), ALICLIENTBACK(
"aliclientback", "alipay client back")
"aliclientback", "alipay client back"),UPMPBACK("upmpback","upmppay back")

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import static java.util.stream.Collectors.toList;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -72,8 +73,9 @@ public final static String format(Map<String, String> paras, String charset) {
*
* @param content
* @return
* @throws UnsupportedEncodingException
*/
public static Map<String, String> parseHttpParas(String content) {
public static Map<String, String> parseHttpParas(String content) throws UnsupportedEncodingException {
Map<String, String> map = new HashMap<>();
int len = content.length();

Expand All @@ -98,4 +100,30 @@ public static Map<String, String> parseHttpParas(String content) {
return map;
}

public static Map<String, String> parseHttpParas(String content, String fromCharset, String toCharset)
throws UnsupportedEncodingException {
Map<String, String> map = new HashMap<>();
int len = content.length();

StringBuilder buf = new StringBuilder(16);
String key = null;
for (int i = 0; i < len; ++i) {
char ch = content.charAt(i);

if (ch == '=') {
key = buf.toString();
buf.setLength(0);
continue;
}
if (ch == '&') {
map.put(key, new String(buf.toString().getBytes(fromCharset), toCharset));
buf.setLength(0);
continue;
}
buf.append(ch);
}
map.put(key, buf.toString());
return map;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
@Service(clazz = "jframe.pay.alipay.service.AlipayServiceImpl", id = "jframe.pay.service.alipay")
public interface AlipayService {

void pay(Map<String, String> req, Map<String, Object> rsp) throws Exception;
void pay(Map<String, String> req, Map<String, Object> rsp) throws Exception;

void payBack(Map<String, String> req, Map<String, Object> rsp)
throws Exception;
void payBack(Map<String, String> req, Map<String, Object> rsp) throws Exception;

void clientPayBack(Map<String, String> req, Map<String, Object> rsp)
throws Exception;
// TODO
void clientPayBack(Map<String, String> req, Map<String, Object> rsp) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
*/
package jframe.pay.dao.service;

import org.apache.ibatis.session.SqlSession;

import jframe.core.plugin.annotation.InjectService;
import jframe.core.plugin.annotation.Injector;
import jframe.memcached.client.MemcachedService;
import jframe.mybatis.MultiMybatisService;
import jframe.pay.domain.dao.OrderAlipay;
import jframe.pay.domain.dao.OrderUpmp;
import jframe.pay.domain.dao.OrderWx;
import jframe.pay.domain.dao.UsrAccount;
import jframe.pay.domain.dao.mapper.Environment;

import org.apache.ibatis.session.SqlSession;

/**
* @author dzh
* @date Sep 2, 2015 2:47:02 AM
Expand Down Expand Up @@ -114,4 +115,35 @@ public OrderWx selectOrderWxWithOrderNo(String orderNo) {
}
}

@Override
public OrderUpmp selectOrderUpmp(String payNo) {
try (SqlSession session = MultiMybatisSvc.getSqlSessionFactory(Environment.RUN_RO1).openSession()) {
return session.selectOne("jframe.pay.domain.dao.mapper.OrderMapper.selectOrderUpmp", payNo);
}
}

@Override
public OrderUpmp selectOrderUpmpWithOrderNo(String orderNo) {
try (SqlSession session = MultiMybatisSvc.getSqlSessionFactory(Environment.RUN_RO1).openSession()) {
return session.selectOne("jframe.pay.domain.dao.mapper.OrderMapper.selectOrderUpmpWithOrderNo", orderNo);
}
}

@Override
public int updateOrderUpmp(OrderUpmp od) {
try (SqlSession session = MultiMybatisSvc.getSqlSessionFactory(Environment.RUN).openSession()) {
int sum = session.update("jframe.pay.domain.dao.mapper.OrderMapper.updateOrderUpmp", od);
session.commit();
return sum;
}
}

@Override
public void insertOrderUpmp(OrderUpmp od) {
try (SqlSession session = MultiMybatisSvc.getSqlSessionFactory(Environment.RUN).openSession()) {
session.insert("jframe.pay.domain.dao.mapper.OrderMapper.insertOrderUpmp", od);
session.commit();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package jframe.pay.dao.service;

import jframe.pay.domain.dao.OrderAlipay;
import jframe.pay.domain.dao.OrderUpmp;
import jframe.pay.domain.dao.OrderWx;

/**
Expand All @@ -29,4 +30,12 @@ public interface OrderDao {

int updateOrderWx(OrderWx od);

void insertOrderUpmp(OrderUpmp od);

OrderUpmp selectOrderUpmp(String payNo);

OrderUpmp selectOrderUpmpWithOrderNo(String orderNo);

int updateOrderUpmp(OrderUpmp od);

}
6 changes: 6 additions & 0 deletions jframe-pay/jframe-pay-plugin/jframe-pay-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn</groupId>
<artifactId>jframe-pay-upmp</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;

import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -77,7 +79,7 @@ protected AbstractHandler() {

private Map<String, List<String>> _params;

private StringBuilder data;
protected StringBuilder data;

// private ByteBufOutputStream data;

Expand Down Expand Up @@ -152,15 +154,15 @@ protected void readHttpRequest(HttpRequest msg) throws Exception {
// TODO buf
protected void readHttpContent(HttpContent msg) throws Exception {
StringBuilder buf = data == null ? data = new StringBuilder() : data;
buf.append(msg.content().toString(CharsetUtil.UTF_8));
buf.append(msg.content().toString(getReqCharset()));
if (msg instanceof LastHttpContent) {
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Dispatch req map {}",
LOG.debug("Dispatch req buf->{} req->{}", buf.toString(),
parseHttpReq(URLDecoder.decode(buf.toString(), HttpConstants.UTF8)));
}

String content = URLDecoder.decode(buf.toString(), HttpConstants.UTF8);
String content = parseReqContent(buf.toString());
if (isValidData(content)) {
service(parseHttpReq(content), rspMap);
} else {
Expand All @@ -175,6 +177,14 @@ protected void readHttpContent(HttpContent msg) throws Exception {
}
}

protected String parseReqContent(String content) throws UnsupportedEncodingException {
return URLDecoder.decode(content, HttpConstants.UTF8);
}

protected Charset getReqCharset() {
return CharsetUtil.UTF_8;
}

protected boolean isValidData(String data) {

return Objects.nonNull(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
*/
package jframe.pay.http.ord;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Map;

import io.netty.util.CharsetUtil;
import jframe.pay.domain.http.ReqOp;
import jframe.pay.domain.http.RspCode;
import jframe.pay.domain.util.HttpUtil;
Expand Down Expand Up @@ -43,6 +46,8 @@ protected void doService(Map<String, String> req, Map<String, Object> rsp) throw
// }
// });
svc.wxback(req, rsp);
} else if (ReqOp.UPMPBACK.code.equals(reqOp)) {
svc.upmpback(req, rsp);
} else {
RspCode.setRspCode(rsp, RspCode.FAIL_HTTP_REQOP);
throw new PayException("Not found");
Expand All @@ -66,4 +71,23 @@ protected Map<String, String> parseHttpReq(String content) throws Exception {
return req;
}

@Override
protected String parseReqContent(String content) throws UnsupportedEncodingException {
return ReqOp.UPMPBACK.code.equals(getReqOp()) ? content : super.parseReqContent(content);
}

@Override
protected Charset getReqCharset() {
return ReqOp.UPMPBACK.code.equals(getReqOp()) ? CharsetUtil.ISO_8859_1 : super.getReqCharset();
}

// private Map<String, String> fromParameters() {
// Map<String, String> map = new HashMap<>();
// getPara().forEach((k, v) -> {
// if (v != null && v.size() > 0)
// map.put(k, v.get(0));
// });
// return map;
// }

}
Loading

0 comments on commit 69003a6

Please sign in to comment.