Alipay.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\controller\Base;
  16. use think\Controller;
  17. use think\Db;
  18. use think\Model;
  19. use Alipay\EasySDK\Kernel\Factory;
  20. use Alipay\EasySDK\Kernel\Util\ResponseChecker;
  21. use Alipay\EasySDK\Kernel\Config;
  22. /**
  23. * 支付宝支付
  24. * Class Member
  25. * @package app\api\controller
  26. */
  27. class Alipay extends Base
  28. {
  29. /**
  30. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  31. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  32. * @throws \GuzzleHttp\Exception\GuzzleException
  33. * 支付宝支付
  34. */
  35. public static function ali_pay($subject,$outTradeNo,$totalAmount,$notifyUrl){
  36. Factory::setOptions(self::getOptions($notifyUrl));
  37. try {
  38. //2. 发起API调用(以支付能力下的统一收单交易创建接口为例)
  39. //$result = Factory::payment()->common()->create("iPhone6 16G", "20200326235526001", "88.88", "2088002656718920");
  40. $result = Factory::payment()->App()->pay($subject,$outTradeNo , $totalAmount);
  41. $responseChecker = new ResponseChecker();
  42. //3. 处理响应或异常
  43. if ($responseChecker->success($result)) {
  44. return $result->body;
  45. } else {
  46. echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
  47. }
  48. } catch (Exception $e) {
  49. return false;
  50. }
  51. }
  52. public static function ali_pay_pc($subject='商品',$outTradeNo,$totalAmount,$notifyUrl,$returnUrl){
  53. Factory::setOptions(self::getOptions($notifyUrl));
  54. try {
  55. $result = Factory::payment()->Page()->pay($subject,$outTradeNo,$totalAmount,$returnUrl);
  56. $responseChecker = new ResponseChecker();
  57. //3. 处理响应或异常
  58. if ($responseChecker->success($result)) {
  59. return $result->body;
  60. } else {
  61. echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
  62. }
  63. } catch (Exception $e) {
  64. return false;
  65. }
  66. }
  67. /**
  68. * 支付宝支付退款
  69. */
  70. public static function ali_refund($outTradeNo,$totalAmount){
  71. Factory::setOptions(self::getOptions(''));
  72. $result = Factory::payment()->common()->refund($outTradeNo,$totalAmount);
  73. $responseChecker = new ResponseChecker();
  74. return $responseChecker->success($result);
  75. }
  76. /**
  77. * 单笔转账到支付宝账户
  78. */
  79. public static function ali_withdrawal($out_biz_no,$trans_amount,$identity,$name){
  80. require_once env('root_path').'/vendor/aop/AopCertClient.php';
  81. require_once env('root_path').'/vendor/aop/request/AlipayFundTransUniTransferRequest.php';
  82. $aop = new \AopCertClient();
  83. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  84. $aop->appId = '2021002142672998';
  85. $aop->rsaPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCTKpmmpfu6Hrn5xIm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RnndvWg/PIfCHhLGRS0jEwUoLTaOxFEhlPbnUjr3IXrRmEUx8xZrZe+XDS/5GPRD6Wj4Rl4Zay1bWNRP3S+QNC+wZdsHZNuHwgUvOde0eXzEPN9C1vnSePWFlByv8NAoGAFXyo16y26Fxq+pr/5Wjki037Wh9lE9M5+TavHXpV+CGnGwZQntVQVSQNDzVk1dg+SYGyd88DwakwbM5Sgy87dqmmPRp+ZYuZDiKbxFBk9es0NL1luV6LUoxUGe7bsVwj2X2IFtKz/qAi7OvW3UdygxVA2GhpJUfEjwRr9Wc1h38CgYEAyTcugtxt6WIT1MtepWwxMgasiuEQgAYY0oQ/tgPxBqZyz5Pkm9yJNsyrvgNfBZFTdexqkby80UGksXt24WsPfhVinTmtuNo8/JOgKkFU4BR3rirfqGB11o/83Z52XFne7D+rR9a1XP4mT+Q+yLQWOT0ETo2+712/+86uUW+rjj8=';
  86. $aop->alipayrsaPublicKey='';
  87. $aop->apiVersion = '1.0';
  88. $aop->signType = 'RSA2';
  89. $aop->postCharset='UTF-8';
  90. $aop->format='json';
  91. $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  92. //支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt
  93. $alipayCertPath = 'ali_cert/alipayCertPublicKey_RSA2.crt';
  94. //调用getPublicKey从支付宝公钥证书中提取公钥 alipayCertPath
  95. $aop->alipayrsaPublicKey =$aop->getPublicKey($alipayCertPath);
  96. // 应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt
  97. $appCertPath = 'ali_cert/appCertPublicKey_2021002142672998.crt';
  98. //调用getCertSN获取证书序列号
  99. $aop->appCertSN = $aop->getCertSN($appCertPath);
  100. //支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt
  101. $rootCertPath = 'ali_cert/alipayRootCert.crt';
  102. //调用getRootCertSN获取支付宝根证书序列号
  103. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);
  104. $orderData= array(
  105. 'out_biz_no' => $out_biz_no,// 订单号
  106. 'trans_amount' => $trans_amount, // 提现实际金额
  107. 'product_code' => "TRANS_ACCOUNT_NO_PWD",
  108. 'biz_scene' => 'DIRECT_TRANSFER',
  109. 'payee_info' => [
  110. 'identity' => $identity,// 收款人帐户
  111. 'identity_type' => 'ALIPAY_LOGON_ID',
  112. 'name' => $name, // 收款人姓名
  113. ],
  114. 'remark' => "提现", // 转帐备注
  115. );
  116. $request = new \AlipayFundTransUniTransferRequest();
  117. $request->setBizContent(json_encode($orderData));
  118. $result = $aop->execute($request);
  119. //var_dump($result);exit();
  120. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  121. $resultCode = $result->$responseNode->code;
  122. if(!empty($resultCode)&&$resultCode == 10000){
  123. return true;
  124. } else {
  125. return false;
  126. }
  127. }
  128. public static function getOptions($notifyUrl){
  129. $options = new Config();
  130. $options->protocol = 'https';
  131. $options->gatewayHost = 'openapi.alipay.com';
  132. $options->signType = 'RSA2';
  133. $options->appId = '2021002141666136';
  134. // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
  135. $options->merchantPrivateKey = 'MIIEpQIBAAKCAQEAhAunpRNIX2PaDe3wdTtMaWtUOGYBRUHBUTDdrwPbhJf7wd76EfUh6T/C6N+PcMjvsN6BJpMy/PqiP9aLKaY6W0oXaTILmTNk6v/Qdn+hLcrLhzN3sd+X9mZCcilc7o3/AKZkupcM2BguDoGugpdrhALmoRe20gDC0+0mLBTzBaA3VXxkPn9DXhl+ggsM7jy6SyMRwbC5EaQALnbtlitYhbdaZmloR5fDIsVkt2xPAHoJMG8nuTOEc213BxV/aS23ek6mwCUmZLvRvZvu/ODyHw1jhCRRzmPSI6ANezr8odY++ZTxzv6qHukKFCLF7RlzaNRzKgE8QfQ4yEO2EFPg1wIDAQABAoIBABC0dMICfX5r4HMwreH23YTcqiv0Y6bCWdWOrAz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OUfd10chcIczjH1AtoRWbF/DLFBdYvBtS0N6JEdTD0UCYK/WH169hrXc247ycXGba6gPK2xq7oM3Zcso60+ibB+HEtTsrePTZlVDRNwsLmCnc=';
  136. /*$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
  137. $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
  138. $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';*/
  139. //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
  140. $options->alipayPublicKey ='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn/i44o8b1xAA8M026tGsl4gagl8Otx0r4pC69KP3dsaL2i7OS2a3lP9mLpQ/S1awqflc8TWGeLqxffUy/L4aF2zYuq17jeuwxfN0uc+8cxX8QvwhGUuWVt/u1MgdLjij5OOk1dgEy6s0EIhefFpOKX9WGSwOqa9rbstqt7grTJXexEIJ+gBvsQ/Vem32wwZMrzSsb7NNwuXMl+/j2RAf1zhnrvZUKQfdiSYuXtWYnLM2MJS258sMC0+q2ImKwhl5Oibt05xaFpL+gBBkyT3Jr+tkU3pcJXraoyhtXnCD0dNTTdr0xpLZsIEzEwoLgeX4XCa7iF3hQArgmmG3kAUNSQIDAQAB';
  141. //可设置异步通知接收服务地址(可选)
  142. $options->notifyUrl = $notifyUrl;
  143. //可设置AES密钥,调用AES加解密相关接口时需要(可选)
  144. $options->encryptKey = "";
  145. return $options;
  146. }
  147. public static function getOptions_test($notifyUrl){
  148. $options = new Config();
  149. $options->protocol = 'https';
  150. $options->gatewayHost = 'openapi.alipay.com';
  151. $options->signType = 'RSA2';
  152. $options->appId = '2021002142672998';
  153. // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
  154. $options->merchantPrivateKey = 'MIIEogIB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oXCOPTI09qgp8MVJJgjLGBg0h09pSWN4XqyEGob4ja5Ej9vgS5g6Sa8opQU89LF6Evkz78aKFaOefLhGe6DR1rhjvgNHzxhGIEWPcLlFMyv6WErCjRMnUGuFVuYz6mzY+orJsolcS2LFk7oqx3MaQBJXU5tr8QKBgFTfD26QzcXFQhdsypIS9cmiDYHSolq9RLcaQRDfPkUnP6U0Jdbsf4/88vny101HocdPegSuOKL4mKnuBbZl/eHxKM3ODePY2zBmu0Qfst/3RR0IhJ8p9quFQkhMQ1+NNXO/S/7CsoLukk6KDl7nfW4hCvTTSIBvC1kfJm4Y3eUxAoGAB1FUyyZuSS5EQIRWmFktbGCGiAGBxu71yq2Fqmal/ggPGLLWFM3Gy4ISkTjbxshQzCvDxJOyDLl8+96NeTFjRb7CC2yoCgDUNe5/z7YgNlHggx5SKWcw3tqxDc1maMvp6tkNEX/VC6ePidxrEL4fM8jb+VFLXv1B1W4Ekr9fmJw=';
  155. /*$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
  156. $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
  157. $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';*/
  158. //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
  159. $options->alipayPublicKey ='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn/i44o8b1xAA8M026tGsl4gagl8Otx0r4pC69KP3dsaL2i7OS2a3lP9mLpQ/S1awqflc8TWGeLqxffUy/L4aF2zYuq17jeuwxfN0uc+8cxX8QvwhGUuWVt/u1MgdLjij5OOk1dgEy6s0EIhefFpOKX9WGSwOqa9rbstqt7grTJXexEIJ+gBvsQ/Vem32wwZMrzSsb7NNwuXMl+/j2RAf1zhnrvZUKQfdiSYuXtWYnLM2MJS258sMC0+q2ImKwhl5Oibt05xaFpL+gBBkyT3Jr+tkU3pcJXraoyhtXnCD0dNTTdr0xpLZsIEzEwoLgeX4XCa7iF3hQArgmmG3kAUNSQIDAQAB';
  160. //可设置异步通知接收服务地址(可选)
  161. $options->notifyUrl = $notifyUrl;
  162. //可设置AES密钥,调用AES加解密相关接口时需要(可选)
  163. $options->encryptKey = "";
  164. return $options;
  165. }
  166. //保证金支付回调
  167. public function deposit_notify()
  168. {
  169. $result = input('post.');
  170. if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
  171. $pay_no = $result['out_trade_no'];
  172. // 用户支付成功处理
  173. $order_info = Db::name('store_deposit_order')->where('pay_no',$pay_no)->where('status',0)->find();
  174. if(empty($order_info)){
  175. return false;
  176. }
  177. Db::table('store_deposit_order')->where('pay_no',$order_info['pay_no'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
  178. $wid = Db::table('store_deposit_order')->where('pay_no',$order_info['pay_no'])->value('worker_id');
  179. //更新是否缴纳保证金
  180. Db::name('store_worker')->where('id',$wid)->update(array('deposit'=>1));
  181. //添加运输路线
  182. $county_arr = explode(',',$order_info['county']);
  183. foreach ($county_arr as $area){
  184. $city_id = Db::name('store_area')->where('id',$area)->value('pid');
  185. $province_id = Db::name('store_area')->where('id',$city_id)->value('pid');
  186. $area_data = array(
  187. 'worker_id' => $wid,
  188. 'start_province_id' => $order_info['start_province'],
  189. 'start_city_id' => $order_info['start_city'],
  190. 'start_county_id' => $order_info['start_county'],
  191. 'end_province_id' => $province_id,
  192. 'end_city_id' => $city_id,
  193. 'end_county_id' => $area
  194. );
  195. Db::name('store_serve_area')->insert($area_data);
  196. }
  197. return true; // 返回处理完成
  198. } else {
  199. }
  200. }
  201. //自动报价支付回调
  202. public function offer_notify()
  203. {
  204. $result = input('post.');
  205. if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
  206. $pay_no = $result['out_trade_no'];
  207. // 用户支付成功处理
  208. $order_info = Db::name('store_offer_order')->where('pay_no',$pay_no)->where('status',0)->find();
  209. if(empty($order_info)){
  210. return false;
  211. }
  212. Db::table('store_offer_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
  213. $order_info = Db::table('store_offer_order')->where('pay_no',$pay_no)->find();
  214. //添加接单人员自动报价信息
  215. $offer_time = Db::name('store_worker')->where('id',$order_info['worker_id'])->value('offer_time');
  216. $offer_timestamp = 0;
  217. if($order_info['type'] == 1){
  218. $offer_timestamp = strtotime('next month');
  219. }elseif($order_info['type'] == 2){
  220. $offer_timestamp = strtotime('+3 month');
  221. }elseif ($order_info['type'] == 3){
  222. $offer_timestamp = strtotime('+1years');
  223. }
  224. if($offer_time && $offer_time > time()){
  225. $offer_timestamp = $offer_timestamp + ($offer_time - time());
  226. }
  227. Db::name('store_worker')->where('id',$order_info['worker_id'])->update(array('offer_time'=>$offer_timestamp));
  228. return true; // 返回处理完成
  229. } else {
  230. }
  231. }
  232. //PC端雇主下单支付回调
  233. public function order_notify()
  234. {
  235. $result = input('post.');
  236. if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
  237. $pay_no = $result['out_trade_no'];
  238. // 用户支付成功处理
  239. $order_info = Db::name('store_order')->where('pay_no',$pay_no)->where('status',1)->find();
  240. if(empty($order_info)){
  241. return false;
  242. }
  243. // 用户支付成功处理
  244. $order_info = Db::name('store_order')->field('id,worker_id')->where('pay_no',$pay_no)->find();
  245. Db::startTrans();
  246. $res = Db::table('store_order')->where('id',$order_info['id'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>2]);
  247. $error = 0;
  248. if(!$res){
  249. $error = 1;
  250. Db::rollback();
  251. }
  252. $pay_obj = new Pay();
  253. if($order_info['worker_id']) {
  254. $rebate_res = $pay_obj->serve_rebate($order_info['id']);
  255. if (!$rebate_res['code']) {
  256. $error = 2;
  257. Db::rollback();
  258. }
  259. }
  260. if($error == 0){
  261. Db::commit();
  262. }
  263. return true; // 返回处理完成
  264. } else {
  265. }
  266. }
  267. //PC端充值余额支付
  268. public function balance_notify()
  269. {
  270. $result = input('post.');
  271. if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
  272. $pay_no = $result['out_trade_no'];
  273. // 用户支付成功处理
  274. $order_info = Db::name('store_balance_order')->where('pay_no',$pay_no)->where('status',0)->find();
  275. if(empty($order_info)){
  276. return false;
  277. }
  278. // 用户支付成功处理
  279. $order_info = Db::name('store_balance_order')->where('pay_no',$pay_no)->find();
  280. Db::startTrans();
  281. $res = Db::table('store_balance_order')->where('user_id',$order_info['user_id'])->where('pay_no',$order_info['pay_no'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
  282. $error = 0;
  283. if(!$res){
  284. $error = 1;
  285. Db::rollback();
  286. }
  287. $balance_data = array(
  288. 'amount' => $order_info['price_total'],
  289. 'user_id' => $order_info['user_id'],
  290. 'order_id' => $order_info['id'],
  291. 'status' => 1
  292. );
  293. $balance_list = Db::name('store_balance_list')->insert($balance_data);
  294. if(!$balance_list){
  295. $error = 2;
  296. Db::rollback();
  297. }
  298. $member_balance = Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance',$order_info['price_total']);
  299. if(!$member_balance){
  300. $error = 3;
  301. Db::rollback();
  302. }
  303. $member_balance_all = Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance_all',$order_info['price_total']);
  304. if(!$member_balance_all){
  305. $error = 4;
  306. Db::rollback();
  307. }
  308. if($error == 0){
  309. Db::commit();
  310. }
  311. return true; // 返回处理完成
  312. } else {
  313. }
  314. }
  315. //PC雇主端增加费用
  316. public function expenses_order_notify()
  317. {
  318. $result = input('post.');
  319. if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
  320. $pay_no = $result['out_trade_no'];
  321. // 用户支付成功处理
  322. $order_info = Db::name('store_expenses_order')->where('pay_no',$pay_no)->where('status',0)->find();
  323. if(empty($order_info)){
  324. return false;
  325. }
  326. // 用户支付成功处理
  327. $order_info = Db::name('store_expenses_order')->field('id,order_id,price_total,reason')->where('pay_no',$pay_no)->find();
  328. // 用户支付成功处理
  329. Db::startTrans();
  330. $expenses_order_res = Db::table('store_expenses_order')->where('id',$order_info['id'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
  331. $error = 0;
  332. if(!$expenses_order_res){
  333. $error = 1;
  334. Db::rollback();
  335. }
  336. $pay_obj = new Pay();
  337. $rebate_res = $pay_obj->add_serve_rebate($order_info['id']);
  338. if(!$rebate_res){
  339. $error = 2;
  340. Db::rollback();
  341. }
  342. $store_order_info = Db::name('store_order')->field('price_total,price_amount')->where('id',$order_info['order_id'])->find();
  343. $store_order_res = Db::name('store_order')->where('id',$order_info['order_id'])->update(['expenses_time'=>date('Y-m-d H:i:s'),'expenses_pay_type'=>1,'expenses_amount'=>$order_info['price_total'],'expenses_reason'=>$order_info['reason'],'price_total'=>$store_order_info['price_total'] + $order_info['price_total'],'price_amount'=>$store_order_info['price_amount'] + $order_info['price_total']]);
  344. if(!$store_order_res){
  345. $error = 3;
  346. Db::rollback();
  347. }
  348. if($error == 0){
  349. Db::commit();
  350. }else{
  351. Db::rollback();
  352. }
  353. return true; // 返回处理完成
  354. } else {
  355. }
  356. }
  357. }