package util.sign;

import android.content.Context;
import android.text.TextUtils;

import java.util.Map;

import beer.brew.vendingmachine.payment.data.AlipayOrder;
import beer.brew.vendingmachine.util.AssertUtils;
import beer.brew.vendingmachine.util.GsonUtils;

public class SignUtils {
    public static String sign(Context context, AlipayOrder order) throws Exception {
        AlipayConfig alipayConfig = getAlipayConfigFromAssert(context);
        Map<String, String> params = OrderInfoUtil.buildOrderParamMap(alipayConfig.getAppId(), GsonUtils.toJsonString(order));
        String orderParam = OrderInfoUtil.buildOrderParam(params);
        String sign = OrderInfoUtil.getSign(params, alipayConfig.getRsaPrivate());

        return orderParam + "&" + sign;
    }

    private static AlipayConfig getAlipayConfigFromAssert(Context context) throws Exception {
        AlipayConfig alipayConfig = AssertUtils.getContentFromAssert(context, AssertUtils.ASSERT_ALIPAY_CONFIG, AlipayConfig.class);
        if (alipayConfig == null
                || TextUtils.isEmpty(alipayConfig.getAppId())
                || TextUtils.isEmpty(alipayConfig.getRsaPrivate())) {
            throw new Exception("AlipayConfig should not be null!");
        }

        return alipayConfig;
    }
}

@@ -143,20 +143,18 @@
 ine.
-payment.data
+data.model
 .Ali
@@ -252,17 +252,17 @@
 ne.util.
-G
+J
 sonUtils
@@ -546,17 +546,17 @@
 ppId(), 
-G
+J
 sonUtils
@@ -562,22 +562,16 @@
 s.toJson
-String
 (order))

replace GsonUtils in SignUtils