Java判断苹果内购支付是否成功

import net.sf.json.JSONObject;
/**
 * 苹果支付
 */
public  class IosPalUtils {

	/**
     * @param key  支付Id第三方返回的orderId
     */
    public  static Boolean isSuccess(String key) {
        try {
            Boolean ok=false;
            if (key!=null) {
                key = key.replace(" ", "+");
                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;
                        }
                    }
                }
            }
            return ok;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }

}

你可能感兴趣的:(Java)