/**
* 主入口
* @param array $params 支付参数, 具体如下
* @param string $params['subject'] 订单标题
* @param string $params['out_trade_no'] 订单商户号
* @param float $params['total_amount'] 订单金额
*/
public static function pay($params)
{
// 1.校检参数
self::checkParams($params);

// 2.构造参数
$payRequestBuilder = new \AlipayTradeAppPayContentBuilder();
$payRequestBuilder->setSubject($params['subject']);
$payRequestBuilder->setOutTradeNo($params['out_trade_no']);
$payRequestBuilder->setTotalAmount($params['total_amount']);
$payRequestBuilder->setTimeExpress('30m');

// 3.获取配置
//$config = config('alipay');
$config=alipay_confing();//传入支付宝参数
$return_url = $params['redirect_url'];

$notify_url = $config['notify_url'];
$payResponse = new \AlipayAppPayTradeService($config);
// dump(666);die;

// 4.进行请求
$result=$payResponse->appPay($payRequestBuilder,$return_url,$notify_url);

//$result="111";
//header("location:".$result);

return $result;
}
  /**
* alipay.trade.app.pay
* @param $builder 业务参数,使用buildmodel中的对象生成。
* @param $return_url 同步跳转地址,公网可访问
* @param $notify_url 异步通知地址,公网可以访问
* @return $response 支付宝返回的信息
*/
function appPay($builder,$return_url,$notify_url,$type='') {

$biz_content=$builder->getBizContent();
//打印业务参数
$this->writeLog($biz_content);

$request = new AlipayTradeAppPayRequest();

$request->setNotifyUrl($notify_url);
$request->setReturnUrl($return_url);
$request->setBizContent ( $biz_content );

// 首先调用支付api
$response = $this->aopclientRequestExecute ($request,true);

// $response = $response->alipay_trade_wap_pay_response;
//$result=htmlspecialchars($response);
return $response;
}
  function aopclientRequestExecute($request,$ispage=false) {

$aop = new AopClient ();
$aop->gatewayUrl = $this->gateway_url;
$aop->appId = $this->appid;
$aop->rsaPrivateKey = $this->private_key;
$aop->alipayrsaPublicKey = $this->alipay_public_key;
$aop->apiVersion ="1.0";
$aop->postCharset = $this->charset;
$aop->format= $this->format;
$aop->signType=$this->signtype;
// 开启页面信息输出
$aop->debugInfo=true;

$result = $aop->sdkExecute($request);

//打开后,将报文写入log文件
$this->writeLog("response: ".var_export($result,true));
return $result;
}
    /**
* 生成用于调用收银台SDK的字符串
* @param $request SDK接口的请求参数对象
* @return string
* @author guofa.tgf
*/
public function sdkExecute($request) {

$this->setupCharsets($request);

$params['app_id'] = $this->appId;
$params['method'] = $request->getApiMethodName();
$params['format'] = $this->format;
$params['sign_type'] = $this->signType;
$params['timestamp'] = date("Y-m-d H:i:s");
$params['alipay_sdk'] = $this->alipaySdkVersion;
$params['charset'] = $this->postCharset;

$version = $request->getApiVersion();
$params['version'] = $this->checkEmpty($version) ? $this->apiVersion : $version;

if ($notify_url = $request->getNotifyUrl()) {
$params['notify_url'] = $notify_url;
}

$dict = $request->getApiParas();
$params['biz_content'] = $dict['biz_content'];

ksort($params);

$params['sign'] = $this->generateSign($params, $this->signType);

foreach ($params as &$value) {
$value = $this->characet($value, $params['charset']);
}

return http_build_query($params);
}