微信发送红包

//发送红包start
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';

//获取openID
$uid = $list['uid'];
$result  = pdo_fetch("SELECT openid FROM ims_meepo_online_user WHERE id=:id",array(':id'=>$uid));
$open_id = $result['openid'];
$money   = (int)$list['money'];

$package = array();
$package['nonce_str'] = random(8);
$package['mch_billno'] = 'ydl'.rand(10000000000000,99999999999999);
$package['mch_id'] = '1515256111';
$package['wxappid'] = 'wx57a837f1e72026c3';
$package['send_name'] = 'xxxx';
$package['re_openid'] = $open_id;
$package['total_amount'] = $money*100;
$package['total_num'] = 1;
$package['wishing'] = 'xxxxxx'.date('Y-m-d');
$package['client_ip'] = CLIENT_IP;
$package['act_name'] = 'xxxxx';
$package['remark'] = 'xxxxxxxxxxxx.';

ksort($package, SORT_STRING);
$string1 = '';
foreach($package as $key => $v) {
if (empty($v)) {
continue;
}
$string1 .= "{$key}={$v}&";
}
$string1 .= "key=2nHuHsDijB4Ye7mNN22QxFAP3AW6l3hT";

$package['sign'] = strtoupper(md5($string1));
$dat = array2xml($package);

load()->func('communication');

$certPath = 'xxxxxx/cert/apiclient_cert.pem';
$keyPath = 'xxxxxx/cert/apiclient_key.pem';

$extra = array(
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_SSL_VERIFYHOST=>false,
CURLOPT_SSLCERTTYPE=>'PEM',
CURLOPT_SSLKEYTYPE=>'PEM',
CURLOPT_SSLCERT=>$certPath,
CURLOPT_SSLKEY=>$keyPath,
CURLOPT_POST=>1
);
$response = ihttp_request($url, $dat, $extra);

// print_r($response);
// exit;

// echo $response;

获取小程序二维码

function getCode(){
    $post = $this->input->post();
    $openid = $post['openid'];
    $token = json_decode($this->get_token('wx725d23dc9ddc4223','8d5971b6282b271b23474849cb3ea562','client_credential'),true);
    $token_str = $token['access_token'];

    $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$token_str";
    $data = array("scene"=>"1001");
    $file_code = $this->https_request($url, json_encode($data));

    $filename = 'uploadfile/qrcode/'.$openid.'.png';
    file_put_contents($filename,$file_code);

    echo 'https://yj.chuanyinhulian.com/'.$filename;
}

function get_token($appid, $secret, $grant_type){
    $url = "https://api.weixin.qq.com/cgi-bin/token?appid=$appid&secret=$secret&grant_type=$grant_type";
    return $this->https_request($url);
}

function https_request($url, $data = null)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}