package com.sdk.sms;

import java.util.HashMap;
import java.util.Map;

import android.text.TextUtils;

import com.lordcard.common.util.DialogUtils;
import com.lordcard.common.util.JsonHelper;
import com.lordcard.entity.JsonResult;
import com.lordcard.network.http.HttpRequest;
import com.sdk.util.sms.SmsOrder;
import com.sdk.util.sms.SmsUtil;
import com.sdk.util.vo.PayPoint;

public class ComSmsPayUtils {
	
	/**
	 * 閫氱敤鐭俊鏀粯
	 */
	public static void goPay(final PayPoint point,final String paySiteTag){
		new Thread() {
			public void run() {
				String value = point.getValue();
				if(TextUtils.isEmpty(value)) return;
				
				// 鍏堟彁浜ゅ厖鍊艰鍗?
				Map<String, String> paramMap = new HashMap<String, String>();

				paramMap.put("goodsName", point.getName()); 	//璐拱鐨勭墿鍝佸悕绉?
				paramMap.put("money",String.valueOf(point.getMoney()));
				paramMap.put("payTag",paySiteTag);		//鍏呭€肩殑鏍囪瘑浣?
				paramMap.put("smsCode",value);			//涓氬姟浠g爜
				
				// 鍚庡彴鐢熸垚璁㈠崟
				String resultJson = HttpRequest.addPayOrder(SmsConfig.COMSMS_URL, paramMap);
				if (TextUtils.isEmpty(resultJson)) {
					return;
				}
				JsonResult result = JsonHelper.fromJson(resultJson, JsonResult.class);
				if (JsonResult.SUCCESS.equals(result.getMethodCode())) {
					SmsOrder order = JsonHelper.fromJson(result.getMethodMessage(), SmsOrder.class);
					
					SmsUtil.goPay(point.getSmsCall(), order.getSmsTxt(), order, paySiteTag);
				} else {
					DialogUtils.mesTip(result.getMethodMessage(), true);
				}

			};
		}.start();
	}
}