package cn.stylefeng.rest.ijpay.iosUtil;
|
|
import net.sf.json.JSONObject;
|
/**
|
* 苹果支付
|
*/
|
public class IosPalUtils {
|
|
/*public static String buyAppVerify(String receipt, String environment) {
|
String url = null;
|
if(environment.equals("0")) {
|
url = "https://buy.itunes.apple.com/verifyReceipt"; // 生产环境
|
}
|
if (environment.equals("1")) {
|
url = "https://sandbox.itunes.apple.com/verifyReceipt"; // 沙盒测试
|
}
|
try {
|
SSLContext sc = SSLContext.getInstance("SSL");
|
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() },new java.security.SecureRandom());
|
URL console = new URL(url);
|
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
|
conn.setSSLSocketFactory(sc.getSocketFactory());
|
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
|
conn.setRequestMethod("POST");
|
conn.setRequestProperty("Content-type", "application/json");
|
conn.setDoInput(true);
|
conn.setDoOutput(true);
|
BufferedOutputStream hurlBufOus = new BufferedOutputStream(
|
conn.getOutputStream());
|
String newReceipt = receipt.replace(" ", "+");
|
String str = String.format("{\"receipt-data\":\"" + newReceipt + "\"}");
|
hurlBufOus.write(str.getBytes());
|
hurlBufOus.flush();
|
|
InputStream is = conn.getInputStream();
|
BufferedReader reader = new BufferedReader(
|
new InputStreamReader(is));
|
String line = null;
|
StringBuffer sb = new StringBuffer();
|
while ((line = reader.readLine()) != null) {
|
sb.append(line);
|
}
|
return sb.toString();
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
return null;
|
}*/
|
|
/**
|
* @param key 支付Id第三方返回的orderId
|
*/
|
public static Boolean isSuccess(String key) {
|
try {
|
System.out.println("!!!!!!!!!!!"+key+"!!!!!!!!!!!");
|
Boolean ok=false;
|
if (key!=null) {
|
key = key.replace(" ", "+");
|
System.out.println("!!!!!!!!!!!"+key+"!!!!!!!!!!!");
|
JSONObject data = JSONObject.fromObject("{\"receipt-data\":\"" + key + "\"}");
|
String score = HttpUtilIOS.sendPosturl("https://buy.itunes.apple.com/verifyReceipt", data);
|
// 将String 转化为json
|
JSONObject json = JSONObject.fromObject(score);
|
System.out.print("!!!!!!!!!!!"+json+"!!!!!!!!!!!");
|
|
if (!json.getString("status").equals("0")) {
|
JSONObject data1 = JSONObject.fromObject("{\"receipt-data\":\"" + key + "\"}");
|
String score1 = HttpUtilIOS.sendPosturl("https://sandbox.itunes.apple.com/verifyReceipt", data1);
|
// 将String 转化为json
|
JSONObject json1 = JSONObject.fromObject(score1);
|
if (json1.getString("status").equals("0")) {
|
String receipt = json1.getString("receipt");
|
JSONObject jsons = JSONObject.fromObject(receipt);
|
String m3 = jsons.getString("in_app");
|
String m4 = m3.replace("[", "");
|
String m5 = m4.replace("]", "");
|
if(m5!=null){
|
ok=true;
|
}
|
}
|
}else {
|
if (json.getString("status").equals("0")) {
|
String receipt = json.getString("receipt");
|
JSONObject jsons = JSONObject.fromObject(receipt);
|
String m3 = jsons.getString("in_app");
|
String m4 = m3.replace("[", "");
|
String m5 = m4.replace("]", "");
|
if(m5!=null){
|
ok=true;
|
}
|
}
|
}
|
}
|
return ok;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
}
|