thinkphp5 PHP支付宝 手机支付,APP支付,提现

<?php

namespace app\payment\alipay;

use think\Log;

class Alipay
{

    //手机支付
    public static function mobilePay($arr)
    {

        vendor('alipay.AopSdk');

        $aop = new \AopClient;
        $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";

        $aop->appId = "";
        $aop->rsaPrivateKey = "";
        $aop->alipayrsaPublicKey = "";
        $aop->format = "json";
        $aop->charset = "UTF-8";
        $aop->signType = "RSA2";

        $request = new \AlipayTradeWapPayRequest();

        $body = $arr['body'];
        $subject = $arr['subject'];
        $order_no = $arr['order_no'];
        $money = $arr['money'];

        //SDK已经封装掉了公共参数,这里只需要传入业务参数
        $bizcontent = "{'body':'{$body}',"
            . "\"subject\": \"$subject\","
            . "\"out_trade_no\": \"$order_no\","
            . "\"timeout_express\": \"30m\","
            . "\"total_amount\": \"$money\","
            . "\"product_code\":\"QUICK_MSECURITY_PAY\""
            . "}";

        $request->setNotifyUrl("回调地址");
        $request->setBizContent($bizcontent);

        $result = $aop->pageExecute($request);
        return $result;

    }

    //APP支付
	public static function pay($arr)
	{

		vendor('alipay.AopSdk');

		$aop = new \AopClient;
		$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";

		$aop->appId = "";

		$aop->rsaPrivateKey = "";
		$aop->format = "json";
		$aop->charset = "UTF-8";
		$aop->signType = "RSA2";
		$aop->alipayrsaPublicKey = "";

		$request = new \AlipayTradeAppPayRequest();

		$body = $arr['body'];
		$subject = $arr['subject'];
		$order_no = $arr['order_no'];
		$money = $arr['money'];

		//SDK已经封装掉了公共参数,这里只需要传入业务参数
		$bizcontent = "{'body':'{$body}',"
			. "\"subject\": \"$subject\","
			. "\"out_trade_no\": \"$order_no\","
			. "\"timeout_express\": \"30m\","
			. "\"total_amount\": \"$money\","
			. "\"product_code\":\"QUICK_MSECURITY_PAY\""
			. "}";

		$request->setNotifyUrl("回调地址");
		$request->setBizContent($bizcontent);
		$response = $aop->sdkExecute($request);

		if($response)
		{
			return $response;
		}else{
			return false;
		}

	}

    //支付回调
	public static function notify()
	{
		vendor('alipay.AopSdk');
		$aop = new \AopClient;
		$aop->alipayrsaPublicKey = "";
		$flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
		return $flag;
	}

	/*
	 * 转账到支付宝账户
	 */
	public static function transferAccounts($money,$account,$order_no)
	{
		vendor('alipay.AopSdk');
		$aop = new \AopClient;
		$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
		$aop->appId = "";
		$aop->rsaPrivateKey = "";
		$aop->alipayrsaPublicKey = "";
		$aop->apiVersion = '1.0';
		$aop->signType = 'RSA2';
		$aop->postCharset='UTF-8';
		$aop->format='json';
		$request = new \AlipayFundTransToaccountTransferRequest ();
		$request->setBizContent("{" .
			"\"out_biz_no\":\"$order_no\"," .
			"\"payee_type\":\"ALIPAY_LOGONID\"," .
			"\"payee_account\":\"$account\"," .
			"\"amount\":\"$money\"," .
			"\"remark\":\"转账\",".
			"  }");
		$result = $aop->execute($request);
		$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
		$resultCode = $result->$responseNode->code;
		if(!empty($resultCode)&&$resultCode == 10000){
			return true;
		} else {
			$encode = json_encode($result->$responseNode);
			$decode = json_decode($encode,true);
			return $decode;
		}
	}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值