CAMPAIGN MONITOR

时间:2015-06-08 14:01:15

标签: php json rest

下面是我发送的json编码数据(但我正在传递数组)。 这些字段都不是空的。它在LIST中创建,但仍然抛出" 类CS_REST_Wrapper_Result的对象无法转换为字符串"

我无法删除上述错误。

{" EmailAddress":" amal_pushp_1@7days.com","姓名":" Amal Pushp"," CustomFields& #34;:[{" Key":"名字","价值":" Amal"},{" Key& #34;:"姓氏","价值":" Pushp"},{" Key":"客户ID&# 34;,"值":" 27221"},{"键":"创建""值&#34 ;: " 08-06-2015"},{" Key":" Landing Page"," Value":" SIGN-UP& #34;},{" Key":" Lead Capture页面","价值":" SIGN-UP"},{&# 34; Key":"订阅类型","价值":"每月"},{" Key":"订阅状态","价值":"有效"},{"密钥":"邮政编码","价值&# 34;:" 110002"},{"键":"学生""值":5},{"钥匙及#34;:"上次付款日期","价值":" 29-05-2015"},{"密钥":&# 34;下一个付款日期","价值":" 29-06-2015"},{"密钥&#3 4;:"工作表总数已完成","价值":" 0"},{" Key":" 01学生姓名& #34;"值":" Amal_pushp_111"},{"键":" 01Student-ID""值&# 34;:" 27222"},{"键":" 01Student年""值":" 0&#34 ;},{"键":" 01Student-工作表完成的""值":" 0"},{"密钥":" 01Student-受试者""值":"数学及#34;},{"键":" 02Student -name""值":" Amal_pushp_112"},{"键":" 02Student-ID""值":" 27223"},{"键":" 02Student年""值":" 0& #34;},{"键":" 02Student-工作 片完成的""值":" 0"},{"键":" 02Student-受试者"&#34 ;值":"英语"},{"键":" 03Student-名称""值":" Amal_pushp_113"},{"键":" 03Student-ID""值":" 27224"},{&#34 ;关键":" 03Student年""值":" 0"},{"键":" 03Student-工作表完成的""值":" 0"},{"键":" 03Student-受试者",& #34;价值":"所有主题"},{" Key":" 04学生姓名","价值":& #34; Amal_pushp_114"},{"键":" 04Student-ID""值":" 27225"},{ "键":" 04Student年""值":" 0"},{"键":& #34; 04Student-工作表完成的""值":" 0"},{"键":" 04Student-受试者&#34 ;,"价值":"所有主题"},{" Key":" 05学生姓名","价值&#34 ;:" Amal_pushp_115"},{"密钥":" 05Student-ID""值":" 27226"},{"键":" 05Student - 年""值":" 0"},{"键":" 05Student-工作表完成的"&# 34;值":" 0"},{"键":" 05Student-受试者""值":&#34 ;数学及#34;}],"重新订阅":真}

1 个答案:

答案 0 :(得分:0)

require_once 'csrest_subscribers.php';
$subscriber_class = new CS_REST_Subscribers($cm['list_id'], $cm['api_key']);
$cm_custom_fields = array( 
                array('Key' => 'First name','Value' => ''),                     
                array('Key' => 'Last name','Value' => ''),                      
                array('Key' => 'Customer ID','Value' => ''),                    
                array('Key' => 'Created','Value' => ''),                        
                array('Key' => 'Trial length','Value' => ''),                   
                array('Key' => 'Lead Capture page','Value' => ''),              
                array('Key' => 'Subscription Type','Value' => ''),              /* 6  */
                array('Key' => 'Subscription Status','Value' => ''),            
                array('Key' => 'Postcode','Value' => ''),                                           array('Key' => 'Students','Value' => ''),                       /* 9  */        
                array('Key' => 'Subscription start date','Value' => ''),        
                array('Key' => 'Next Payment Date','Value' => ''),              
                array('Key' => 'Total Worksheets Completed','Value' => ''),     
                array('Key' => '01Student-Name' ,'Value' => ''),                
                array('Key' => '01Student-Id'   ,'Value' => ''),                
                array('Key' => '01Student-Year' ,'Value' => ''),                
                array('Key' => '01Student-Worksheets-Completed' ,'Value' => ''),    
                array('Key' => '01Student-Subjects' ,'Value' => ''),            
                array('Key' => '02Student-Name' ,'Value' => ''),                
                array('Key' => '02Student-Id'   ,'Value' => ''),                
                array('Key' => '02Student-Year' ,'Value' => ''),                
                array('Key' => '02Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '02Student-Subjects' ,'Value' => ''),            
                array('Key' => '03Student-Name' ,'Value' => ''),                
                array('Key' => '03Student-Id'   ,'Value' => ''),                
                array('Key' => '03Student-Year' ,'Value' => ''),                
                array('Key' => '03Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '03Student-Subjects' ,'Value' => ''),            
                array('Key' => '04Student-Name' ,'Value' => ''),                
                array('Key' => '04Student-Id' ,'Value' => ''),                  
                array('Key' => '04Student-Year' ,'Value' => ''),                
                array('Key' => '04Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '04Student-Subjects' ,'Value' => ''),            
                array('Key' => '05Student-Name' ,'Value' => ''),                
                array('Key' => '05Student-Id' ,'Value' => ''),                  
                array('Key' => '05Student-Year' ,'Value' => ''),                
                array('Key' => '05Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '05Student-Subjects' ,'Value' => ''),            
                array('Key' => 'Sign up page','Value' => '')                    
            );
function cm_active_trial_user($parent_id,$cm_custom_fields){
    $stripe_customer  = Stripe_Customer::retrieve($parent_id);
    $subs_obj         = $stripe_customer['subscriptions']['data'][0];
    $total_students   = '0';
    $student_default_counter = 13;
    $plan_type = mysql_fetch_assoc(mysql_query("select (CASE WHEN plan_type ='2' THEN 'MONTHLY'
    WHEN plan_type = '3' THEN 'ANNUAL' ELSE 'NA' END) AS pt from ep_subscription_parent where parent_id='".$parent_id."'"));
    $qry = mysql_query("select id, fname, lname, post_code, email, subject, auto_assign_subject, user_type, date_modified, student_year from ep_wsusers where id='".$parent_id."' or parent_id='".$parent_id."' order by id") or mysql_error();
    $count = mysql_num_rows($qry) or mysql_error();
    $subject_array=array('1'=>'MATHS','2'=>'ENGLISH','3'=>'SCIENCE','9'=>'ALL SUBJECTS');
    if($count>=0){
        while($cm_parent_student=mysql_fetch_assoc($qry))
        {

            $landing_page ='SIGN-UP';
            if($cm_parent_student['user_type']=='parent'){
                $cm_email = $cm_parent_student['email'];
                $cu       = $this->objectToArray($this->get("'".$cm_email."'"));
                $cm_custom_fields[0]['Value']  = $cm_parent_student['fname'];
                $cm_custom_fields[1]['Value']  = $cm_parent_student['lname'];
                $cm_custom_fields[2]['Value']  = $cm_parent_student['id'];
                $cm_custom_fields[3]['Value']  = date('d-m-Y');
                $cm_custom_fields[4]['Value']  = $cu['response']['CustomFields'][4]['Value'];
                $cm_custom_fields[5]['Value']  = $cu['response']['CustomFields'][5]['Value'];
                $cm_custom_fields[6]['Value']  = $plan_type['pt'];
                $cm_custom_fields[8]['Value']  = $cm_parent_student['post_code'];                   
                $cm_custom_fields[10]['Value'] = $cu['response']['CustomFields'][10]['Value'];
                $cm_custom_fields[38]['Value'] = $cu['response']['CustomFields'][38]['Value'];      
                $cm_name    = ucfirst(trim($cm_custom_fields[0]['Value'].' '.$cm_custom_fields[1]['Value']));
                $parent = mysql_fetch_assoc(mysql_query("select sum(is_complete) as total_ws from  ep_wsassigned where parentId='".$parent_id."' and is_complete='1'"));
                $total_ws = ($parent['total_ws']!='')?$parent['total_ws']:'0';
                $cm_custom_fields[12]['Value']=$total_ws;
            }else{
                $total_students=$total_students+1;
                $subject_id     =($cm_parent_student['subject'])?$cm_parent_student['subject']:$cm_parent_student['auto_assign_subject'];
                $cm_student_name= ucfirst(trim($cm_parent_student['fname'].' '.$cm_parent_student['lname']));
                $cm_custom_fields[$student_default_counter++]['Value']= $cm_student_name;
                $cm_custom_fields[$student_default_counter++]['Value']= $cm_parent_student['id'];
                $student_year = ($cm_parent_student['student_year'])?$cm_parent_student['student_year']:'0';
                $cm_custom_fields[$student_default_counter++]['Value']= $student_year;
                $student = mysql_fetch_assoc(mysql_query("select sum(is_complete) as total_ws from  ep_wsassigned where studentId='".$cm_parent_student['id']."' and is_complete='1'"));
                $total_ws = ($student['total_ws']!='')?$student['total_ws']:'0';
                $cm_custom_fields[$student_default_counter++]['Value']= $total_ws;
                $cm_custom_fields[$student_default_counter++]['Value']= $subject_array[$subject_id];
            }
        }
        $cm_custom_fields[9]['Value'] = "$total_students";
        if($is_trial || $subs_obj['status']=='trialing'){
            $cm_custom_fields[7]['Value']   = 'TRIAL';
            $cm_custom_fields[11]['Value']  = date('d-m-Y',$subs_obj['trial_end']);
        }else if($subs_obj['status']=='active'){
            $cm_custom_fields[7]['Value']   = 'ACTIVE';
            $cm_custom_fields[11]['Value']  = date('d-m-Y',$subs_obj['current_period_end']);
        }
        $msg = $this->cm_subscriber('new',$cm_email,$cm_name,$cm_custom_fields);
    }else{
        $msg = 'No Record Found!';
    }
    return $msg;
}

function cm_subscriber($action,$email,$name,$array_subscriber){
    if(count($array_subscriber)>0){
        /*
        foreach($array_subscriber as $key=>$value){
            if($value){
                $key=$value;
            }else{
                unset($key,$value);
            }
        }       
        echo '<pre>';
        print_r($array_subscriber);
        foreach($array_subscriber as $key=>$object){
            if($object['Value']==''){
                unset($array_subscriber[$key]);
            }
        }
        print_r($array_subscriber);
        */  
        if($action=='new'){ /* Creates New Subscription */
            $new_subscriber = array(
                        'EmailAddress' => $email,
                        'Name' => $name,
                        'CustomFields' => $array_subscriber,
                        'Resubscribe' => true
                    );          
            $msg = $this->add($new_subscriber);
        }else if($action=='update'){
            $update_custom_fields = array( 'CustomFields' => $array_subscriber  );
            $msg = $this->update($email, $update_custom_fields);
        }       
    }else{
        $msg = 'error';
    }
    return $msg;
}

function add($subscriber) {
return $this->post_request($this->_subscribers_base_route.'.json', $subscriber);
}