PHP实现微信提现(企业付款到零钱)

怎么开通企业付款到零钱?

有的商户号的产品中心是没有这个功能的,不过,该功能的pid(product id)是5,只要随便进去某一个产品,在地址栏把pid改为5。

即可进入该功能页面,进行开通,不过要满足条件。

用户提现代码:

//用户微信提现
 private function withdrawals_weixin($id){
    $falg = M('withdrawals')->where(['id'=>$id])->find();
    $openid = M('users')->where('user_id', $falg['user_id'])->value('openid');
    $data['openid'] = $openid;
    $data['pay_code'] = $falg['id'].$falg['user_id'];
    $data['desc'] = '提现ID'.$falg['id'];
    if($falg['taxfee'] >= $falg['money']){
      return array('status'=>1, 'msg'=>"提现额度必须大于手续费!" );
    }else{
      $data['money'] = bcsub($falg['money'], $falg['taxfee'], 2);
    }
    include_once PLUGIN_PATH . "payment/weixin/weixin.class.php";
    $weixin_obj = new \weixin();
    $result = $weixin_obj->transfer($data);
   
    return $result;
 }

其中pay_code在商户号的提现功能是唯一的,所以为了防重放攻击,这个值千万不能用随机数,最好用ID,具有提现记录唯一。

提现逻辑代码:

// 微信提现转账
  function transfer($data){
    
    header("Content-type: text/html; charset=utf-8");
    //CA证书及支付信息
   $wxchat['appid'] = WxPayConfig::$appid;
   $wxchat['mchid'] = WxPayConfig::$mchid;
 
   $wxchat['api_cert'] = PLUGIN_PATH.'/payment/weixin/cert/apiclient_cert.pem';
    $wxchat['api_key'] = PLUGIN_PATH.'/payment/weixin/cert/apiclient_key.pem';
    
    // $wxchat['api_ca'] = '/plugins/payment/weixin/cert/rootca.pem';
   $webdata = array(
    'mch_appid' => $wxchat['appid'],
    'mchid'   => $wxchat['mchid'],
    'nonce_str' => md5(time()),
    //'device_info' => '1000',
    'partner_trade_no'=> $data['pay_code'], //商户订单号,需要唯一
    'openid' => $data['openid'],//转账用户的openid
    'check_name'=> 'NO_CHECK', //OPTION_CHECK不强制校验真实姓名, FORCE_CHECK:强制 NO_CHECK:
    //'re_user_name' => 'jorsh', //收款人用户姓名
    'amount' => $data['money'] * 100, //付款金额单位为分
    'desc'  => $data['desc'],
    'spbill_create_ip' => request()->ip(),
    );
  
   foreach ($webdata as $k => $v) {
   $tarr[] =$k.'='.$v;
    }
 
   sort($tarr);
   $sign = implode($tarr, '&');
   $sign .= '&key='.WxPayConfig::$key;
    $webdata['sign']=strtoupper(md5($sign));
    
    $wget = $this->array2xml($webdata);
    
    $pay_url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
 
    $res = $this->http_post($pay_url, $wget, $wxchat);
 
   if(!$res){
   return array('status'=>1, 'msg'=>"Can't connect the server" );
   }
    $content = simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA);
    
   if(strval($content->return_code) == 'FAIL'){
   return array('status'=>1, 'msg'=>strval($content->return_msg));
   }
   if(strval($content->result_code) == 'FAIL'){
   return array('status'=>1, 'msg'=>strval($content->err_code),':'.strval($content->err_code_des));
    }
 
   $rdata = array(
    'mch_appid'    => strval($content->mch_appid),
    'mchid'      => strval($content->mchid),
    'device_info'   => strval($content->device_info),
    'nonce_str'    => strval($content->nonce_str),
    'result_code'   => strval($content->result_code),
    'partner_trade_no' => strval($content->partner_trade_no),
    'payment_no'    => strval($content->payment_no),
    'payment_time'   => strval($content->payment_time),
   );
   return $rdata;
 
  }
      

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/5511.html