MoneyService.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\service;
  3. use think\Exception;
  4. class MoneyService
  5. {
  6. private $model = '';
  7. /**
  8. * 初始化方法
  9. */
  10. public function __construct()
  11. {
  12. $this->model = new \app\common\model\User();
  13. }
  14. //提现转账(新版2020-01-01)
  15. public function withdrawTransfer($params=[]) {
  16. $result = [
  17. 'status' => 1,
  18. 'msg' => '',
  19. 'data' => [],
  20. ];
  21. try {
  22. $money = isset($params['money']) ? $params['money'] : '';
  23. $alipayAccount= isset($params['alipay_account']) ? $params['alipay_account'] : '';
  24. $name= isset($params['name']) ? $params['name'] : '';
  25. $out_biz_no = isset($params['out_biz_no']) ? $params['out_biz_no'] : getMillisecond() . mt_rand(1, 1000);
  26. $payTest = config('pay_test');
  27. if ($payTest == 1) {
  28. // $money = 0.1;
  29. }
  30. $info = [
  31. 'money' => $money,
  32. 'alipay_account' => $alipayAccount,
  33. 'name' => $name,
  34. ];
  35. $data['out_biz_no'] = $out_biz_no; //商户订单号
  36. $data['trans_amount'] = $info['money']; //订单总金额,单位为元,精确到小数点后两位
  37. $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';//业务产品码,收发现金红包固定为:STD_RED_PACKET;单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD;单笔无密转账到银行卡固定为:TRANS_BANKCARD_NO_PWD
  38. $data['biz_scene'] = 'DIRECT_TRANSFER'; //描述特定的业务场景,可传的参数如下:PERSONAL_COLLECTION:C2C现金红包-领红包;DIRECT_TRANSFER:B2C现金红包、单笔无密转账到支付宝/银行卡
  39. $data['order_title'] = 'GG语音提现'; //转账业务的标题,用于在支付宝用户的账单里显示
  40. $data['payee_info'] = [
  41. 'identity' => $info['alipay_account'],//收款方支付宝id或支付宝账户
  42. 'identity_type' => 'ALIPAY_LOGON_ID',//ALIPAY_USER_ID:支付宝会员的用户 ID,可通过 获取会员信息 能力获取。ALIPAY_LOGON_ID:支付宝登录号,支持邮箱和手机号格式。
  43. 'name' => $info['name'],//当 identity_type=ALIPAY_LOGON_ID 时,本字段必填。若传入该属性,则在支付宝回单中将会显示这个属性。
  44. ];
  45. //转账备注(支持200个英文/100个汉字)。当付款方为企业账户,且转账金额达到(大于等于)50000元,remark不能为空。收款方可见,会展示在收款用户的收支详情中。
  46. $data['remark'] = 'GG语音提现';
  47. require_once("../extend/AliPay/AliPay.php");
  48. $alipay =new \AliPay();
  49. $alipayResult =$alipay->AliPayWithdraw($data);
  50. if ($alipayResult['code'] != 10000) {
  51. throw new Exception($alipayResult['sub_msg']);
  52. }
  53. } catch (Exception $e) {
  54. $result['status'] = 0;
  55. $result['msg'] = $e->getMessage();
  56. }
  57. return $result;
  58. }
  59. }