拼接url

//代码已在vs2010运行过。
//如果代码不能运行,应该是vs配置的问题,可自行上百度搜索相关的解决方法
#include<iostream>
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <windows.h>
#include <stdlib.h>
#include<fstream>

#pragma comment(lib,"Wininet.lib")
#include <vector>
#include<string>
using namespace std; 

//long atol(char *s);

void creat_w( char input[64],unsigned long w[80])
{
   int i,j;unsigned long temp,temp1;
   for(i=0;i<16;i++)
          {
             j=4*i;
             w[i]=((long)input[j])<<24 |((long)input[1+j])<<16|((long)input[2+j])<<8|((long)input[3+j])<<0;

          }
   for(i=16;i<80;i++)
         {
             w[i]=w[i-16]^w[i-14]^w[i-8]^w[i-3];
             temp=w[i]<<1;
             temp1=w[i]>>31;
             w[i]=temp|temp1;

         }
   //return '0';
}

char ms_len(long a,char intput[64])
{
    unsigned long temp3,p1;  int i,j;
    temp3=0;
    p1=~(~temp3<<8);
    for(i=0;i<4;i++)
       {
          j=8*i;
          intput[63-i]=(char)((a&(p1<<j))>>j);

       }
	return '0';

}







//字符串插入函数  在字符串string 中查找 source , 找到后再 source之后插入字符串 destination, 找不到则返回 NULL 
static char * insert_string (char * string, const char * source, char* destination )  
{  
    char* sk = strstr (string, source);  
    if (sk == NULL) return NULL;  
    //char* tmp;  
    size_t size = strlen(string)+strlen(destination)+1;  
    char* newstr = (char*)calloc (1, size);  
    if (newstr == NULL) return NULL;  
  
    char* retstr = (char*)calloc (1, size);  
    if (retstr == NULL)  
    {  
        free (newstr);  
        return NULL;  
    }  
    _snprintf(newstr,size-1,"%s",string);  
    sk = strstr (newstr, source);  
  
    int pos = 0;  
    sk += strlen(source);  
  
    memcpy (retstr+pos, newstr, sk - newstr);  
    pos += sk - newstr;  
  
    memcpy (retstr+pos, destination, strlen(destination));  
    pos += strlen(destination);  
    memcpy (retstr+pos, sk, strlen(sk));  
  
    free (newstr);  
    return retstr;  
  
}  

string input_return(char* s1)
{
	ofstream outfile;
	outfile.open("myfile.txt");
	vector<char> v;
	//string text=s1;
	//string method="iss.getTalk";
	//appKey	ukundogckyf5kwbv2wmihaz5425xfc5wtfo4bqyp
	//appSecret	08bc1d6efbb937b51e71928fe5f54066
	//char szUrl[] = "http://117.121.49.45/service/iss?appkey=5rh55ljf6sijrmp4c23xyoaebccjojs4rekljoqu&appver=1&city=%E5%8C%97%E4%BA%AC%E5%B8%82&gps=39.97685%2C116.36043&history=&method=iss.getTalk&text=%E6%98%8E%E5%A4%A9%E7%9A%84%E5%A4%A9%E6%B0%94%EF%BC%9F&time=2015-03-18%2018%3A03%3A41&udid=54d59edc305273984f990823ee150fd1c25dc289&ver=2.0&voiceId=&scenario=&screen=&dpi=&viewid=0&appsig=E58C5622B7A9C79541E85F0EA71A6E172B812B73";
     // char szUrl[]="http://10.10.11.107/6F41015F89599D6C121BE289D6803F698C320354&appkey=ukundogckyf5kwbv2wmihaz5425xfc5wtfo4bqyp&method=iss.getTalk&text=%e4%bb%8a%e5%a4%a9%e5%a4%a9%e6%b0%94%e5%a6%82%e4%bd%95&ver=2.0&appsig=573B5655B56A7B729C704EB7BA19B23DFE906719&6F41015F89599D6C121BE289D6803F698C320354";
	//char szUrl[] = "http://117.121.49.45/service/iss?appkey=5rh55ljf6sijrmp4c23xyoaebccjojs4rekljoqu&appver=1&city=%E5%8C%97%E4%BA%AC%E5%B8%82&gps=39.97685%2C116.36043&history=&method=iss.getTalk&text=s1&time=2015-03-18%2018%3A03%3A41&udid=54d59edc305273984f990823ee150fd1c25dc289&ver=2.0&voiceId=&scenario=&screen=&dpi=&viewid=0&appsig=E58C5622B7A9C79541E85F0EA71A6E172B812B73";
	//  char szUrl[]="http://scv2.hivoice.cn/service/iss?appkey=F99AB60027FF379418DF6A094E83FA03723F92B7&method=iss.getTalk&appkey=test&ver=2.0&udid=124128941928&gps=33.90249,103.234723&appver=1.4.1.800&appsig=test&text=附近有什么好吃的";
	 // char szUrl[]="http://scv2.hivoice.cn/service/iss?4109A0F4790E67302889FFB6F3DF93AA&appkey=ukundogckyf5kwbv2wmihaz5425xfc5wtfo4bqyp&method=iss.getTalk&text=s1&ver=2.0&ver=2.0&appver=1.0.0&4109A0F4790E67302889FFB6F3DF93AA";
	 // char szUrl[]="http://scv2.hivoice.cn/service/iss?appkey=F99AB60027FF379418DF6A094E83FA03723F92B7&method=iss.getTalk&text=%e6%9d%a5%e4%b8%80%e9%a6%96%e6%ad%8c&ver=2.0&udid=8E67302889FFB6F3DF&appver=1.0.0&appsig=4109A0F4790E67302889FFB6F3DF93AA";
	 // char szUrl[]="http://scv2.hivoice.cn/ii.appkey=F99AB60027FF379418DF6A094E83FA03723F92B7&method=iss.getTalk&text=%e6%9d%a5%e4%b8%80%e9%a6%96%e6%ad%8c&ver=2.0&udid=8E67302889FFB6F3DF&appver=1.0.0&appsig=4109A0F4790E67302889FFB6F3DF93AA";
	  //char szUrl[]="http://scv2.hivoice.cn/service/iss?method=iss.getTalk&appkey=test&ver=2.0&udid=124128941928&gps=33.90249,103.234723&appver=1.4.1.800&appsig=test&text=附近有什么好吃的";
	 // char szUrl[]="http://scv2.hivoice.cn/service/iss?12794ca4422a63a21c8584bfb067b424&appKey=zjo6pne4fmgpiketi4c7be2dctjso36hjyaoppip&method=iss.getTalk&text=%e6%9d%a5%e4%b8%80%e9%a6%96%e6%ad%8c&ver=2.0&12794ca4422a63a21c8584bfb067b424&appsig=37356BB7900A7A8EF5865A40D4F5C4615876AAC7";
	  //char suUrl[]="http://scv2.hivoice.cn/service/08bc1d6efbb937b51e71928fe5f54066&appKey=ukundogckyf5kwbv2wmihaz5425xfc5wtfo4bqyp&method=iss.getTalk&text=%e6%9d%a5%e4%b8%80%e9%a6%96%e6%ad%8c&ver=2.0&udid=8E67302889FFB6F3DF&appver=1.0.0&appsig=4109A0F4790E67302889FFB6F3DF93AA&08bc1d6efbb937b51e71928fe5f54066";
	 //char szUrl[]="http://scv2.hivoice.cn/service/iss?08bc1d6efbb937b51e71928fe5f54066&appkey=zjo6pne4fmgpiketi4c7be2dctjso36hjyaoppip&method=iss.getTalk&text=&ver=2.0&08bc1d6efbb937b51e71928fe5f54066&appsig=FF7F6EAC33094241AEE59A578DA8FB9BAA98FD29";



	char szUrl[]="08bc1d6efbb937b51e71928fe5f54066&appkey=zjo6pne4fmgpiketi4c7be2dctjso36hjyaoppip&method=iss.getTalk&text=&ver=2.0&08bc1d6efbb937b51e71928fe5f54066";
	//printf("%s\n",insert_string (szUrl,"text=",s1));
	//szUrl=insert_string (szUrl,"text=",s1);
	//printf("hello\n");
	string lan=insert_string (szUrl,"text=",s1);   //在text后连接用户输入的数据
	string lan2="12794ca4422a63a21c8584bfb067b424&"+lan+"&12794ca4422a63a21c8584bfb067b424&";
	//printf("lan=======%s\n",lan);

	



	unsigned long H0=0x67452301,H1=0xefcdab89,H2=0x98badcfe,H3=0x10325476,H4=0xc3d2e1f0;
   unsigned long A,B,C,D,E,temp,temp1,temp2,temp3,k,f;int i,flag;unsigned long w[80];
   char input[64]; 
   long x;int n;
   //printf("input message:\n");
   //scanf("%s",input);
   n=strlen(input);
   if(n<57)
          {
                 x=n*8;
                 ms_len(x,input);
                 if(n==56)
                     for(i=n;i<60;i++)
                     input[i]=0;
                 else
                    {
                     input[n]=128;
                     for(i=n+1;i<60;i++)
                     input[i]=0;
                    }

          }

   creat_w(input,w);
   /*for(i=0;i<80;i++)
   printf("%lx,",w[i]);*/
   printf("\n");
   A=H0;B=H1;C=H2;D=H3;E=H4;
   for(i=0;i<80;i++)
         {
               flag=i/20;
               switch(flag)
                  {
                   case 0: k=0x5a827999;f=(B&C)|(~B&D);break;
                   case 1: k=0x6ed9eba1;f=B^C^D;break;
                   case 2: k=0x8f1bbcdc;f=(B&C)|(B&D)|(C&D);break;
                   case 3: k=0xca62c1d6;f=B^C^D;break;
                  }
               /*printf("%lx,%lx\n",k,f); */
               temp1=A<<5;
               temp2=A>>27;
               temp3=temp1|temp2;
               temp=temp3+f+E+w[i]+k;
               E=D;
               D=C;

               temp1=B<<30;
               temp2=B>>2;
               C=temp1|temp2;
               B=A;
               A=temp;

              // printf("%lx,%lx,%lx,%lx,%lx\n",A,B,C,D,E);
         }
   H0=H0+A;
   H1=H1+B;
   H2=H2+C;
   H3=H3+D;
   H4=H4+E;
   string lan3=lan2+"appsig=";
   //longatol
   char a1[1000],a2[1000],a3[1000],a4[1000],a0[1000];
   sprintf(a0, "%ld",H0);
   sprintf(a1, "%ld",H1);
   sprintf(a2, "%ld",H2);
   sprintf(a3, "%ld",H3);
   sprintf(a4, "%ld",H4);

   //string lan3;
   //strcpy(lan3,a0);
   string zhou0=a0;
   string zhou1=a1;
   string zhou2=a2;
   string zhou3=a3;
   string zhou4=a4;
   string lan4="http://scv2.hivoice.cn/service/iss?"+lan3+zhou0+zhou1+zhou2+zhou3+zhou4;
   cout<<lan4<<endl;
   //strcpy(dst,src.c_str());
   strcpy(szUrl,lan4.c_str());
   
   cout<<szUrl;
   //outfile<<szUrl<<endl;


	//char szUrl[]="http://scv2.hivoice.cn/service/iss?12794ca4422a63a21c8584bfb067b424&appKey=zjo6pne4fmgpiketi4c7be2dctjso36hjyaoppip&method=iss.getTalk&text=cout<<s1&ver=2.0&12794ca4422a63a21c8584bfb067b424&appsig=2462F8A6D6F2F34CBE707E98A6FB90AA85842039";
	 CHAR szAgent[] = "";
    HINTERNET hInternet1 = 
        InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
    if (NULL == hInternet1)
     {
        InternetCloseHandle(hInternet1);
        return FALSE;
     }
    HINTERNET hInternet2 =InternetOpenUrl(hInternet1,szUrl,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE,NULL);
    if (NULL == hInternet2)
     {
        InternetCloseHandle(hInternet2);
        InternetCloseHandle(hInternet1);
        return FALSE;
     }
    DWORD dwMaxDataLength = 500;
    PBYTE pBuf = (PBYTE)malloc(dwMaxDataLength*sizeof(TCHAR));
    if (NULL == pBuf)
     {
        InternetCloseHandle(hInternet2);
        InternetCloseHandle(hInternet1);
        return FALSE;
     }
    DWORD dwReadDataLength = NULL;
    BOOL bRet = TRUE;
    do 
    {
        ZeroMemory(pBuf,dwMaxDataLength*sizeof(TCHAR));
        bRet = InternetReadFile(hInternet2,pBuf,dwMaxDataLength,&dwReadDataLength);
        for (DWORD dw = 0;dw < dwReadDataLength;dw++)
         {
            v.push_back(pBuf[dw]);
         }
     } while (NULL != dwReadDataLength);

	outfile<<szUrl<<endl;



    vector<char>::iterator i_j;
    for(i_j=v.begin(); i_j!=v.end(); i_j++)
	{
        //printf("%c",*i_j);
		outfile<<*i_;
	}
	//Sleep(100000);
	outfile<<szUrl<<endl;
	outfile.close();
	return lan4;
}


int main()
{
	char s1[10000];
	cin>>s1;
    printf("%s\n",input_return(s1));
    return 0;
} 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。