PHP实现微信企业自动打款

本文介绍了如何使用PHP调用微信商户平台的接口实现企业自动打款功能,关键在于使用证书并以XML格式发送数据,同时需确保在商户平台开通此功能且90天内有企业流水。
摘要由CSDN通过智能技术生成

关于企业付款可以阅读微信商户平台的相关介绍
网址:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1
根据官网文档的介绍。用到的微信官方接口是
https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
而实现这个功能是必须要证书的。(重点)而且需要传递的数据格式为xml类型

 /**
     * 发送xml
     *
     * @param string $trade_no
     *            订单号
     * @param string $open_id
     *            微信openid
     * @param string $re_user_name
     *            真实姓名
     * @param string $amount
     *            金额
     * @return boolean
     */
    public function sendXml($trade_no, $open_id, $re_user_name, $amount)
    {
   
        $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
        $mch_appid = config('weixin.app_id');
        $mch_id = config('weixin.mch_id');
        $secrect_key = config('weixin.api_secret');
        $data = array(
            'mch_appid' => $mch_appid, // 商户账号appid
            'mchid' => $mch_id, // 商户号
            'nonce_str' => $this->nonce_str(), // 随机字符串
            'partner_trade_no' => $trade_no, // 商户订单号
            'openid' => $open_id, // 用户openid
            'check_name' => 'NO_CHECK', // 校验用户姓名选项,
            're_user_name' => $re_user_name, // 收款用户姓名
            
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好,关于企业微信机器人的开发,可以使用PHP开发语言进行实现企业微信机器人可以实现自动回复、事件监听等功能,具体实现方式可以参考企业微信开发文档。 在PHP中,可以使用企业微信提供的API接口进行开发。首先需要在企业微信后台创建一个应用,并获取到应用的ID和Secret。然后可以使用企业微信提供的API接口进行消息发送、用户管理等操作。 以下是一个简单的PHP企业微信机器人代码示例: ```php <?php // 设置企业微信应用ID和Secret $appId = 'your_app_id'; $appSecret = 'your_app_secret'; // 获取access_token $accessToken = getAccessToken($appId, $appSecret); // 处理接收到的消息 $postData = file_get_contents('php://input'); $msgData = json_decode($postData, true); if (!empty($msgData)) { $msgType = $msgData['MsgType']; switch ($msgType) { case 'text': // 处理文本消息 $content = $msgData['Content']; $replyContent = '您发送的消息是:' . $content; sendTextMessage($msgData['FromUserName'], $replyContent, $accessToken); break; case 'event': // 处理事件消息 $eventType = $msgData['Event']; if ($eventType == 'subscribe') { // 处理关注事件 $replyContent = '欢迎关注!'; sendTextMessage($msgData['FromUserName'], $replyContent, $accessToken); } break; } } // 获取access_token function getAccessToken($appId, $appSecret) { $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$appId&corpsecret=$appSecret"; $response = file_get_contents($url); $result = json_decode($response, true); return $result['access_token']; } // 发送文本消息 function sendTextMessage($userId, $content, $accessToken) { $url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$accessToken"; $data = array( 'touser' => $userId, 'msgtype' => 'text', 'text' => array('content' => $content), ); $postData = json_encode($data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/json', 'content' => $postData, 'timeout' => 15 * 60, ), ); $context = stream_context_create($options); $response = file_get_contents($url, false, $context); return $response; } ``` 以上代码实现了一个简单的企业微信机器人,可以通过收到的文本消息进行自动回复,也可以处理关注事件等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值