如何用PHP实现微信公众号企业转账功能?

2026-04-02 20:281阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计842个文字,预计阅读时间需要4分钟。

如何用PHP实现微信公众号企业转账功能?

企业付款提供商家直接收款功能,支持用户微信零钱支付能力,同时支持平台操作及接口调用两种方式,资金到账速度快,使用及查询方便。主要用来解决商家对用户付款需求,如:保险理赔等。

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

特点

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

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

如何用PHP实现微信公众号企业转账功能?

下面是程序截图:

第一步:设置配置参数

$url='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 = i') && !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 = ' . $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 = '<?xml version="1.0" encoding="utf-8"?>' . $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;

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

本文共计842个文字,预计阅读时间需要4分钟。

如何用PHP实现微信公众号企业转账功能?

企业付款提供商家直接收款功能,支持用户微信零钱支付能力,同时支持平台操作及接口调用两种方式,资金到账速度快,使用及查询方便。主要用来解决商家对用户付款需求,如:保险理赔等。

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

特点

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

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

如何用PHP实现微信公众号企业转账功能?

下面是程序截图:

第一步:设置配置参数

$url='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 = i') && !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 = ' . $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 = '<?xml version="1.0" encoding="utf-8"?>' . $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;

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