package com.neusoft.smart.pos.payment.controller;

import com.neusoft.smart.pos.payment.service.ChinaumsPayServiceNotifyService;
import com.neusoft.smart.pos.payment.utils.ChinaumsUtils;
import com.neusoft.smart.pos.payment.utils.HttpClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping(path = "/chinaumsPayServiceNotify")
public class ChinaumsPayServiceNotifyController {

	@Autowired
	private ChinaumsPayServiceNotifyService chinaumsPayServiceNotifyService;

	/**
	 * 银联商务公众号支付成功回调方法
	 * @return
	 */
	@ApiIgnore
	@RequestMapping(value = "payNotify")
	public String chinaumsPayNotify(HttpServletRequest request){
        Map<String,String> notifyDataMap = ChinaumsUtils.getRequestParams(request);
		return chinaumsPayServiceNotifyService.chinaumsNotifyDataHandle(notifyDataMap);
	}

	/**
	 * 银联商务支付退款成功回调方法
	 * @return
	 */
	@ApiIgnore
	@RequestMapping(value = "refundNotify")
	public String weixinRefundNotify(HttpServletRequest request){
		String notifyXmlData = HttpClientUtils.getStringDataFromRequest(request);
		return chinaumsPayServiceNotifyService.chinaumsRefundNotifyDataHandle(notifyXmlData);
	}

}
	