PHP code example of code-lives / weixin

1. Go to this page and download the library: Download code-lives/weixin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

code-lives / weixin example snippets


composer 


//引入命名空间
use Applet\Assemble\Weixin;

// 微信小程序
$pay= Weixin::init($config)->set("订单号","金额","描述","描述")->getParam();

// 微信公众号【appid 和secret 换成公众号的】
$pay= Weixin::init($config)->set("订单号","金额","描述","openid")->getParam();

// 微信H5【appid 和secret 换成公众号的】
$pay= Weixin::init($config)->set("订单号","金额","描述")->getH5Param();

// 微信APP (没有openid)
$pay= Weixin::init($config)->set("订单号","金额","描述")->getParam();


$data= Weixin::init($config)->getToken();

$code="";
$data= Weixin::init($config)->getOpenid($code);

$data= Weixin::init($config)->decryptPhone($session_key, $iv, $encryptedData);
echo $phone['phoneNumber'];

$data = Weixin::init($config)->findOrder("订单号");

$order = [
        'out_trade_no' => '123',
        'total_fee' => 0.01,
        'out_refund_no' => time(),
        'refund_fee' => 0.01,
    ];
$data= Weixin::init($config)->applyOrderRefund($order);

$data = [
    "touser" => "",
    "template_id" => "",
    "page" => "pages/index/index",
    "miniprogram_state" => "developer",
    "lang" => "zh_CN",
    "data" => [
        'thing6' => ['value' => "第一个参数{{thing6.DATA}}"],
        'thing7' => ['value' => "第二个参数{{thing7.DATA}}"],
        'time8' =>  ['value' => "第三个参数{{time8.DATA}}"],
],
$data= Weixin::init($config)->sendMsg($data,$token);
$data=[
    "errcode" => 0
    "errmsg" => "ok"
    "msgid" => 123456
]

$pay = Weixin::init($config);
$status = $pay->notifyCheck();//验证
if($status){
    $order = $pay->getNotifyOrder();//订单数据
    //$order['out_trade_no']//平台订单号
    //$order['transaction_id']//微信订单号
    echo 'success';exit;
}