侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

php实现微信公众号企业转账功能

微信(小程序)  /  管理员 发布于 7年前   162

企业付款提供由商户直接付钱至用户微信零钱的能力,支持平台操作及接口调用两种方式,资金到账速度快,使用及查询方便。主要用来解决合理的商户对用户付款需求,比如:保险理赔、彩票兑换等等。

特点

  • 发起方式灵活,可通过页面或接口发起
  • 微信消息触达,用户及时获知入账详情
  • 支持实名校验,判断收款人真实身份
  • 通过openid即可实现付款,无需用户敏感隐私信息
  • 到账速度快,在发起后,用户可在几分钟内收到付款

企业转账需要到微信商户平台=》产品中心=》企业付款到零钱,开启此功能

下面是程序截图:

第一步:设置配置参数

$url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';$pars = array();$pars['mch_appid'] =$this->module['config']['appid'];$pars['mchid']=$this->module['config']['mchid'];$pars['nonce_str'] =random(32);$pars['partner_trade_no'] =time().random(3,1);$pars['openid'] =$openid;$pars['check_name'] ='NO_CHECK' ;//$pars['re_user_name'] ='' ;$monet_finall = $price * 100;$pars['amount'] =$monet_finall; //这里是折算成1%的所以要*100$pars['desc'] ='您已成功提现 '.$price.' 现金';$pars['spbill_create_ip'] =$this->module['config']['ip'];ksort($pars, SORT_STRING);$string1 = '';foreach ($pars as $k => $v) {  $string1 .= "{$k}={$v}&";}$string1 .= "key=".$this->module['config']['password'];$pars['sign'] = strtoupper(md5($string1));$xml = array2xml($pars);$extras = array();$extras['CURLOPT_CAINFO'] = ATTACHMENT_ROOT . '/withdraw/cert/rootca.pem.' . $_W['uniacid'];$extras['CURLOPT_SSLCERT'] = ATTACHMENT_ROOT   . '/withdraw/cert/apiclient_cert.pem.' . $_W['uniacid'];$extras['CURLOPT_SSLKEY'] = ATTACHMENT_ROOT . '/withdraw/cert/apiclient_key.pem.' . $_W['uniacid'];$procResult = null;

第二步:CURL请求微信服务器

load()->func('communication');$resp = ihttp_request($url, $xml, $extras);

其中ihttp_request函数内容是:

function ihttp_request($url, $post = '', $extra = array(), $timeout = 60) {  $urlset = parse_url($url);  if (empty($urlset['path'])) {   $urlset['path'] = '/';  }  if (!empty($urlset['query'])) {   $urlset['query'] = "?{$urlset['query']}";  }  if (empty($urlset['port'])) {     }  if (strexists($url, 'https://') && !extension_loaded('openssl')) {   if (!extension_loaded("openssl")) {     message('请开启您PHP环境的openssl');   }  }  if (function_exists('curl_init') && function_exists('curl_exec')) {   $ch = curl_init();   if (!empty($extra['ip'])) {     $extra['Host'] = $urlset['host'];     $urlset['host'] = $extra['ip'];     unset($extra['ip']);   }   curl_setopt($ch, CURLOPT_URL, $urlset['scheme'] . '://' . $urlset['host'] . ($urlset['port'] == '80' || empty($urlset['port']) ? '' : ':' . $urlset['port']) . $urlset['path'] . $urlset['query']);   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);   curl_setopt($ch, CURLOPT_HEADER, 1);   @curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);   if ($post) {     if (is_array($post)) {      $filepost = false;foreach ($post as $name => &$value) {        if (version_compare(phpversion(), '5.6') >= 0 && substr($value, 0, 1) == '@') {         $value = new CURLFile(ltrim($value, '@'));        }        if ((is_string($value) && substr($value, 0, 1) == '@') || (class_exists('CURLFile') && $value instanceof CURLFile)) {         $filepost = true;        }      }      if (!$filepost) {        $post = http_build_query($post);      }     }     curl_setopt($ch, CURLOPT_POST, 1);     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);   }   if (!empty($GLOBALS['_W']['config']['setting']['proxy'])) {     $urls = parse_url($GLOBALS['_W']['config']['setting']['proxy']['host']);     if (!empty($urls['host'])) {      curl_setopt($ch, CURLOPT_PROXY, "{$urls['host']}:{$urls['port']}");      $proxytype = 'CURLPROXY_' . strtoupper($urls['scheme']);      if (!empty($urls['scheme']) && defined($proxytype)) {        curl_setopt($ch, CURLOPT_PROXYTYPE, constant($proxytype));      } else {        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);      }      if (!empty($GLOBALS['_W']['config']['setting']['proxy']['auth'])) {        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['_W']['config']['setting']['proxy']['auth']);      }     }   }   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);   curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);   curl_setopt($ch, CURLOPT_SSLVERSION, 1);   if (defined('CURL_SSLVERSION_TLSv1')) {     curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);   }   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');   if (!empty($extra) && is_array($extra)) {     $headers = array();     foreach ($extra as $opt => $value) {      if (strexists($opt, 'CURLOPT_')) {        curl_setopt($ch, constant($opt), $value);      } elseif (is_numeric($opt)) {        curl_setopt($ch, $opt, $value);      } else {        $headers[] = "{$opt}: {$value}";      }     }     if (!empty($headers)) {      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);     }   }   $data = curl_exec($ch);   $status = curl_getinfo($ch);   $errno = curl_errno($ch);   $error = curl_error($ch);   curl_close($ch);   if ($errno || empty($data)) {     return error(1, $error);   } else {     return ihttp_response_parse($data);   }  }  $method = empty($post) ? 'GET' : 'POST';  $fdata = "{$method} {$urlset['path']}{$urlset['query']} HTTP/1.1\r\n";  $fdata .= "Host: {$urlset['host']}\r\n";  if (function_exists('gzdecode')) {   $fdata .= "Accept-Encoding: gzip, deflate\r\n";  }  $fdata .= "Connection: close\r\n";  if (!empty($extra) && is_array($extra)) {   foreach ($extra as $opt => $value) {     if (!strexists($opt, 'CURLOPT_')) {      $fdata .= "{$opt}: {$value}\r\n";     }   }  }  $body = '';  if ($post) {   if (is_array($post)) {     $body = http_build_query($post);   } else {     $body = urlencode($post);   }   $fdata .= 'Content-Length: ' . strlen($body) . "\r\n\r\n{$body}";  } else {   $fdata .= "\r\n";  }  if ($urlset['scheme'] == 'https') {   $fp = fsockopen('ssl://' . $urlset['host'], $urlset['port'], $errno, $error);  } else {   $fp = fsockopen($urlset['host'], $urlset['port'], $errno, $error);  }  stream_set_blocking($fp, true);  stream_set_timeout($fp, $timeout);  if (!$fp) {   return error(1, $error);  } else {   fwrite($fp, $fdata);   $content = '';   while (!feof($fp))     $content .= fgets($fp, 512);   fclose($fp);   return ihttp_response_parse($content, true);  }}

第三步:解析分析微信服务器返回值并返回。

if (is_error($resp)) {  $procResult = $resp;} else {  $arr=json_decode(json_encode((array) simplexml_load_string($resp['content'])), true);  $xml = '' . $resp['content'];  $dom = new \DOMDocument();  if ($dom->loadXML($xml)) {    $xpath = new \DOMXPath($dom);    $code = $xpath->evaluate('string(//xml/return_code)');    $ret = $xpath->evaluate('string(//xml/result_code)');    if (strtolower($code) == 'success' && strtolower($ret) == 'success') {      $procResult = array('errno'=>0,'error'=>'success');;    } else {      $error = $xpath->evaluate('string(//xml/err_code_des)');      $procResult = array('errno'=>-2,'error'=>$error);    }  } else {    $procResult = array('errno'=>-1,'error'=>'未知错误');  }}return $procResult;

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

您可能感兴趣的文章:

  • PHP实现微信商户支付企业付款到零钱功能
  • Thinkphp 5.0实现微信企业付款到零钱
  • php实现微信支付之企业付款
  • PHP编程实现微信企业向用户付款的方法示例
  • php实现微信企业转账功能
  • 微信企业转账之入口类分装php代码
  • PHP微信企业号开发之回调模式开启与用法示例
  • PHP实现微信公众号企业号自定义菜单接口示例
  • PHP编程之微信公众平台企业号验证接口示例【回调操作】
  • php微信公众号开发之微信企业付款给个人


  • 上一条:
    php提取微信账单的有效信息
    下一条:
    PHP实现微信提现功能
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 微信模板消息改版后发送规则记录(微信订阅消息参数值内容限制说明)(1个评论)
    • 微信支付v3对接所需工具及命令(0个评论)
    • 2023年9月1日起:微信小程序必须备案才能上线运营(0个评论)
    • 腾讯官方客服回应了:微信好友上限约10000个!(1个评论)
    • 2023年做微信小程序的老铁注意:新增收费项、微信小程序获取手机号也收费了(2个评论)
    • 近期文章
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2017-10
    • 2018-01
    • 2020-03
    • 2021-06
    • 2021-10
    • 2022-03
    • 2023-02
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-10
    • 2023-11
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客