123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace Tool\MayouTool\Pay;
- use Tool\MayouTool\Bean\Pay\GetCodePayUrlParamBean;
- use Tool\MayouTool\Exception\PayException;
- use Tool\MayouTool\HttpCurl;
- /**
- * 支付服务类
- * Class PayService
- * @package Tool\MayouTool\Pay
- */
- class PayService
- {
- /**
- * 获取支付二维码接口
- * @param GetCodePayUrlParamBean $bean
- * @return array ["qrcode_url"=>"支付二维码","qr"=>"支付二维码","order_number"=>"订单编号"]
- * @throws PayException
- */
- public static function getCodePayUrlService(GetCodePayUrlParamBean $bean)
- {
- $url = env("OFFICIAL_PAY_URL");
- if(!$url){
- throw new PayException("官方支付地址不能为空");
- }
- if(!$bean->getOrderPrice()){
- throw new PayException("支付金额不能为空");
- }
- if(!$bean->getRelationOrderNumber()){
- throw new PayException("支付关联订单号不能为空");
- }
- if(!$bean->getPayType()){
- throw new PayException("支付类型不能为空");
- }
- if(!$bean->getAppKey()){
- throw new PayException("支付appkey不能为空");
- }
- if(!$bean->getAppSecret()){
- throw new PayException("支付appsecret不能为空");
- }
- $url = $url."v1/pay/codePayUrl";
- $params = [
- "orderPrice"=>$bean->getOrderPrice(),
- "relationOrderNumber"=>$bean->getRelationOrderNumber(),
- "payType"=>$bean->getPayType()
- ];
- $header = [
- "appKey"=>$bean->getAppKey(),
- "appSecret"=>$bean->getAppSecret()
- ];
- $res = HttpCurl::postCurl($url,$params,$header);
- if(!$res["status"]){
- throw new PayException("请换成其他方式充值");
- }
- return $res["data"];
- }
- /**
- * 根据官方订单编号获取订单
- * @param $token string token
- * @param $trade_sn string 官方订单编号
- * @param $amount int 金额(单位为分)
- * @return ["order_sn"=>"淘象订单编号","price"=>"支付金额(单位为分)"]
- */
- public static function getOfficialOrderByOrderNumberService($token, $trade_sn, $amount)
- {
- $url = env("TAOXIANG_PAY_URL");
- if(!$url){
- throw new PayException("淘象支付地址不能为空");
- }
- if(!$token){
- throw new PayException("token不能为空");
- }
- if(!$trade_sn){
- throw new PayException("官方支付单号不能为空");
- }
- if(!$amount){
- throw new PayException("订单金额不能为空");
- }
- $params = [
- "token"=>$token,
- "trade_sn"=>$trade_sn,
- "amount"=>$amount
- ];
- $url = $url."merchant/alipay_apply_quick/forget";
- $res = HttpCurl::postCurl($url,$params);
- if($res["status"]!=0){
- throw new PayException("订单获取失败");
- }
- return $res["data"];
- }
- /**
- * 获取支付方式
- * @param $appKey string appkey
- * @param $appSecret string secret
- */
- public static function getPayMethodService($appKey,$appSecret)
- {
- $url = env("OFFICIAL_PAY_URL");
- if(!$url){
- throw new PayException("官方支付地址不能为空");
- }
- if(!$appSecret){
- throw new PayException("用户不能为空");
- }
- if(!$appKey){
- throw new PayException("用户不能为空");
- }
- $url = $url."v1/pay/method";
- $header = [
- "appKey"=>$appKey,
- "appSecret"=>$appSecret
- ];
- $res = HttpCurl::getCurl($url,[],$header);
- if(!$res["status"]){
- throw new PayException("支付方式失败");
- }
- return $res["data"];
- }
- }
|