This commit is contained in:
kamhung
2015-12-03 13:29:05 +08:00
parent 38d56bd897
commit 85e0271265
2 changed files with 4 additions and 7 deletions

View File

@@ -6,11 +6,11 @@
package com.wentch.redkale.service.weixin; package com.wentch.redkale.service.weixin;
import com.wentch.redkale.convert.json.*; import com.wentch.redkale.convert.json.*;
import static com.wentch.redkale.convert.json.JsonConvert.TYPE_MAP_STRING_STRING;
import com.wentch.redkale.service.*; import com.wentch.redkale.service.*;
import com.wentch.redkale.util.*; import com.wentch.redkale.util.*;
import static com.wentch.redkale.util.Utility.getHttpContent; import static com.wentch.redkale.util.Utility.getHttpContent;
import java.io.*; import java.io.*;
import java.lang.reflect.*;
import java.security.*; import java.security.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
@@ -23,9 +23,6 @@ import javax.annotation.*;
*/ */
public class WeiXinMPService implements Service { public class WeiXinMPService implements Service {
protected static final Type MAPTYPE = new TypeToken<Map<String, String>>() {
}.getType();
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName()); protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
private final boolean finest = logger.isLoggable(Level.FINEST); private final boolean finest = logger.isLoggable(Level.FINEST);
@@ -67,7 +64,7 @@ public class WeiXinMPService implements Service {
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + mpsecrets.get(appid) + "&code=" + code + "&grant_type=authorization_code"; String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + mpsecrets.get(appid) + "&code=" + code + "&grant_type=authorization_code";
String json = getHttpContent(url); String json = getHttpContent(url);
if (finest) logger.finest(url + "--->" + json); if (finest) logger.finest(url + "--->" + json);
Map<String, String> jsonmap = convert.convertFrom(MAPTYPE, json); Map<String, String> jsonmap = convert.convertFrom(TYPE_MAP_STRING_STRING, json);
return getMPUserTokenByOpenid(jsonmap.get("access_token"), jsonmap.get("openid")); return getMPUserTokenByOpenid(jsonmap.get("access_token"), jsonmap.get("openid"));
} }
@@ -75,7 +72,7 @@ public class WeiXinMPService implements Service {
String url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid; String url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid;
String json = getHttpContent(url); String json = getHttpContent(url);
if (finest) logger.finest(url + "--->" + json); if (finest) logger.finest(url + "--->" + json);
Map<String, String> jsonmap = convert.convertFrom(MAPTYPE, json.replaceFirst("\\[.*\\]", "null")); Map<String, String> jsonmap = convert.convertFrom(TYPE_MAP_STRING_STRING, json.replaceFirst("\\[.*\\]", "null"));
return jsonmap; return jsonmap;
} }

View File

@@ -89,7 +89,7 @@ public class WeiXinPayService implements Service {
map.put("appid", wxpayappid); map.put("appid", wxpayappid);
map.put("mch_id", wxpaymchid); map.put("mch_id", wxpaymchid);
map.put("nonce_str", Long.toHexString(System.currentTimeMillis()) + Long.toHexString(System.nanoTime())); map.put("nonce_str", Long.toHexString(System.currentTimeMillis()) + Long.toHexString(System.nanoTime()));
map.put("body", "三万英尺服务套餐"); map.putIfAbsent("body", "服务");
map.put("attach", "" + payid); map.put("attach", "" + payid);
map.put("out_trade_no", "" + orderpayid); map.put("out_trade_no", "" + orderpayid);
map.put("total_fee", "" + paymoney); map.put("total_fee", "" + paymoney);