<?php
//http://dpshop.wandoupao.cn/api/handleOrder.php
//异步订单处理 1 2 模板消息处理 ->用户和客服 3发货处理
error_reporting(0);
define('IN_SYS', true);
require '../framework/bootstrap.inc.php';
load()->func('communication');
//迁移表sq_qianyi 字段 id old_openid new_openid
$Access_token=getAccess_token();//在微擎自己实现了方法
$all_Data= pdo_fetchall("SELECT * FROM ".tablename('sq_qianyi'));
// $all_Data= pdo_fetchall("SELECT * FROM ".tablename('sq_qianyi')." limit 0,1");
$url="https://api.weixin.qq.com/cgi-bin/changeopenid?access_token=$Access_token";//官方的是http 但是会报错注意这里是https
foreach ($all_Data as $key => $value) {
echo $value["id"];
$params=array();
$params["from_appid"]="xxxx";//原账号appid
$params["openid_list"]=array($value["old_openid"]);
$params=json_encode($params);
$res= http_post($url,"POST", $params);
if ($res["http_code"] == 200) {
$newInfo=json_decode($res["response"],true);
$new_openid=$newInfo["result_list"][0]["new_openid"];
$user_data = array(
'new_openid' => $new_openid
);
$result = pdo_update('sq_qianyi', $user_data, array('old_openid' =>$value["old_openid"]));
}
}
function getAccess_token(){//在微擎获取的access_token
$url='xxxxxx';
$token=file_get_contents($url);
return $token;
}
function http_post($url, $method, $postfields = null, $headers = array(), $debug = false)
{
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ci, CURLOPT_TIMEOUT, 30);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
switch ($method) {
case 'POST':
curl_setopt($ci, CURLOPT_POST, true);
if (!empty($postfields)) {
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
//$this->postdata = $postfields;
}
break;
}
curl_setopt($ci, CURLOPT_URL, $url);
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ci, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ci);
$http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
if ($debug) {
var_dump($postfields);
var_dump(curl_getinfo($ci));
var_dump($response);
}
curl_close($ci);
$retData=array();
$retData["http_code"]=$http_code;
$retData["response"]=$response;
return $retData;
}